To separate code and avoid duplication I am trying to split up recurring pieces of twig code into partials (think of a nav or a block of services for example).
I tried using include
but Craft requires me to register a template path. This is also stated in the docs.
I'm not really sure this is the best way to do it since I would litter my "Sections" with "Singles" which would just function as nothing more include templates.
For example in my home.twig
I have the following piece of code:
<div>
<div class="container mx-auto px-4 pb-16">
{% include 'pages/home/dienstenGrid.twig' %}
</div>
</div>
Which would render the corresponding include template. But to be able to do this I have to register this "section"
Something about this feels gross, and I was wondering if there's a better way to go about this issue. If This is the way
I will use it this way (Star Wars: The Mandalorian pun intended)
{{ macros.dienstenGrid() }}
instead? Macros are defined in/craft/templates/partials/macros.twig
as far as I remember – Campiotti Dec 2 at 14:48_
before the name. Just like_partials/home/dienstenGrid.twig
. Then this twig file/template is not visitable by just use the file path. – Parry Huang Dec 3 at 0:05