Example 5: Override the component partial See the live demo for this recipe in action! The official OctoberCMS docs provide an in-depth explanation on how you can override component partials. Here we will describe why you would want to do so with November Gallery, as well as how. Why? If you are well-versed in October, then skip this section and go to "How?"! November Gallery uses templates to generate code into your OctoberCMS page. If you wish to significantly alter the code that is generated, then you will be forced to override the component partial. Doing so may also be easier than trying to add long and complicated settings using the component inspector. How? These code-generation templates are called "Partials" in October lingo, and they can be found in your filesystem after you install November Gallery under the following directory: plugins/zenware/novembergallery. Alternatively, you can find the source code on GitHub (go to components, then check out any of the subfolders). You then need to create a file in your OctoberCMS backend, in the "CMS" area, on the "Partials" page, with the same name as the partial. The file must be "placed" in a directory that has the same name as your component alias. Let's go through this step-by-step. Let's say we wish to override the template for generating a swiper component. We've already dropped the component onto our page. Although this isn't necessary, for the sake of this tutorial let's change the component alias to "mySwiperGallery": Remember, swiper needs to be inside of an element that has a width and a height - so we put it inside of a div that covers the whole viewport. Also, make sure to also rename your component in your page: We then go to "Partials" and create a file called "mySwiperGallery/default.htm" and set copy-paste the original source code for this partial from GitHub. We are going to completely override the javascript that is used to initialize Swiper. We will implement the "Multiple Slides Per View" demo on the Swiper demo website. The source code for that demo is available here. You may in fact find that it's easier to take the demo and copy-paste that into our partial, and replace the needed bits only. You will have to: Make sure any is inside of a {% put scripts %}...{% endput %} twig tag Similarly, surround any content inside of {% put styles %}...{% endput %} Replace that actual list of images in the demo with the following: {% for galleryitem in gallery.items.sortBy('fileName') %}
{% endfor %} Our final complete page looks like this: {% set galleryitems = __SELF__.gallery.items %} {% if __SELF__.error %}
{{ __SELF__.error }}
{% endif %} {% put styles %} {% endput %}
{% for galleryitem in galleryitems.sortBy('fileName') %}
{% endfor %}
{% put scripts %} {% endput %} And voila, you can see that we've gotten the demo up and running using our gallery of images! You can see the demo in action at https://novembergallery.zenware.hu/cookbook/overriding-partials Default Partials Source Code You can find the source code for the partials used by the various November Gallery components below: Gallery Type Default Component Partial Path Embedded Gallery /plugins/zenware/novembergallery/components/embeddedgallery/default.htm Swiper /plugins/zenware/novembergallery/components/swipergallery/default.htm Pop-up Lightbox /plugins/zenware/novembergallery/components/popupgallery/default.htm Video Gallery /plugins/zenware/novembergallery/components/videogallery/default.htm Image List Only /plugins/zenware/novembergallery/components/customgallery/default.htm