Hello there.
I’m trying to migrate html theme to grav theme, and I have some questions about the way to call images from blueprint of theme in twig template.
I have the following:
- blueprint.yaml (in theme path)
- theme.yaml (in user/config/themes)
- partial_file.html.twig (in user/themes/theme/partials)
In blueprint.yaml I have:
form:
validation: loose
fields:
carousel:
type: toggle
label: Carousel
help: If is active, then Carousel is showed.
highlight: 1
default: 0
options:
1: PLUGIN_ADMIN.ENABLED
0: PLUGIN_ADMIN.DISABLED
validate:
type: bool
carousel1:
type: section
title: First carousel image
description: 'First carousel image'
fields:
image:
type: file
label: Image
description: Select an image
destination: 'theme@:/images/slider'
accept:
- image/jpg
title:
type: text
label: Title
text:
type: text
label: Text
button:
type: text
label: Button text
url_button:
type: text
label: Button URL
In them.yaml I have:
enabled: true
carousel: true
carousel1:
title: 'Title 1'
text: 'Lorem Ipsum'
button: 'Services'
url_button: '#services'
image:
user/themes/oxygen/images/slider/1.jpg:
name: 1.jpg
type: image/jpeg
size: 743502
path: user/themes/oxygen/images/slider/1.jpg
In partial_file.html.twig I have:
{% set theme_config = attribute(config.themes, config.system.pages.theme) %}
{% set carousel1 = theme_config.carousel1.image.path %}
....(html code)
<div class="item active" style="background-image: url({{carousel1}}">
...(html code)
I’d like to call the image saved in yaml file, user/themes/oxygen/images/slider/1.jpg, but I think in the background-image css property this method not work correctly.
Do you have another way to call this image in the twig template?
Thanks in advance.