On the main page and some subpages I use Swiper. That’s why I decided to separate
it from main theme.js file and include it via assets manager cms GRAV.
In the directory user/themes/abm/assets/css and user/theme/abm/assets/js I have placed the appropriate files.
In the file user/themes/abm/templates/partials/swiper the code:
On localhost everything works, but after uploading to the server I have the following problem.
After clearing the cache, the page is displayed ok but only the first time. Each subsequent page view and there are no links to Swiper’s .css and .js in the code.
{% include 'partials/head/partials/metadata.html.twig' %}
{% include 'partials/head/partials/favicons.html.twig' %}
{% include 'partials/head/partials/css.html.twig' %}
{% include 'partials/head/partials/js.html.twig' %}
Never_cache_twig: true
in the page frontmatter and works. Thx.
It’s a pity, though, because I thought the following effect could be achieved.
In the Swiper’s twig template, I place references to the css and js files necessary for its operation (as shown above), and then in any other template file, e.g.:
partials/blocks/hero/slider:
{% embed "partials/swiper/swiper.html.twig" with {
swiper: {
container: {
classes: 'swiper-container swiper-hero',
data: 'data-effect="fade" data-margin="0" data-items="1"'
},
}}%}
{% block swiperWrapper %}
{% for image in images %}
{% include "partials/blocks/hero/slider/slide.html.twig" with {
index: loop.index0
}%}
{% endfor %}
{% endblock %}
{% endembed %}
And I don’t have to worry about anything anymore. In the current situation, I have Swiper’s .css and .js files only on pages where it is needed (super), but I have to remember about the proper configuration.