Hi there!
I Need help to utilize the Owl Carousel shortcode plugin.
I’m studying Grav a bit by bit and looking into developed themes.
Now I want to modify a theme, and it has showcase.html.twig
There I’ve pasted all possible Owl Carousel’s options, such as:
what theme are you using/ looking at? maybe i find my answers there. am also trying to figure out how to work with the owl carousel (my post), but from what i understand, markdown shortcode ([owl-carousel]...[/owl-carousel]) can’t be used in a twig file.
but i guess you have tried the regular way in your page edit window (editing the .md file) already, right?
Hi @pamtbaau !
Thank you,
I’ve added process: twig: true
at the very beginning of ‘modular/showcase.html.twig’, but still no luck…
What I’m doing wrong?
@01K, The sample code I showed is the content of a *.md page file (in your case probably ‘_showcase.md’), not a Twig template file (in your case modular/showcase.html.twig).
and not like the other owl-carousels i am using on the same page. no carousel visible. so, i thought, i try to change the twig part to the format i would use in my .md file:
module.html.twig:
{% set carousel = "[owl-carousel items=1 margin=10 loop=true nav=true]" %}
{% for image in page.media.images %}
{% set carousel = carousel~"" %}
{% endfor %}
{% set carousel = carousel~"[/owl-carousel]" %}
{{ carousel|shortcodes }}
@leG, Starting from a fresh installed One-Page skeleton, I did the following:
Installed the Owl Carousel plugin using bin/gpm install shortcode-owl-carousel
Copied image ‘/user/pages/01.home/03._callout/jeep.jpg’ to get 2 images in the page’s folder.
In file ‘/user/themes/quark/templates/modular/text.html.twig’, I replaced line 12:
{{ image.html|raw }}
with:
{% set carousel = "[owl-carousel items=1 nav=true]" %}
{% for image in page.media.images %}
{% set carousel = carousel~"<img src=\""~image.url~"\">" %}
{% endfor %}
{% set carousel = carousel~"[/owl-carousel]" %}
{{ carousel|shortcodes }}
To be sure the webpage is freshly created everytime I refresh the browser, I switched off caching in ‘/user/config/system.yaml’:
cache:
enabled: false
You should now see a working carousel with 2 identical pages when you refresh the browser…
Notes:
Switch caching on when you go in production!
Don’t edit ‘/user/themes/quark/templates/modular/text.html.twig’ as I did, but instead create a child theme to prevent future updates of Quark to override your changes.
@pamtbaau, a little offtop.
I’ve resolved my issue with your help.
Now the images are shown in the way which I want, perfect.
But I want to add a heading/text to a slider. Here comes big problems.
Now this code works fine:
your way was totally on point!
unfortunately for reasons i do not (yet, possibly never) understand, sometimes the carousel is shown, sometimes it’s not. probably has to do with my setup, as i’ve created a bit of a monster customizing the basic quark theme beyond recognition.
(i hope nobody will ever look at my code. )
@01K, That is because the size of the <div> containing the background image, doesn’t determine its size based on the image, but on the title and paragraph inside the div.
Alternatives:
Easiest: You could give the <div> a fixed height: height: 300px;
A bit harder: Or use the <img> element which will cause the div to resize to its contents. This makes it a bit harder to position the caption over the image and keeping the carousel layout in order…