We can use snippets as a kind of modules. We can then call the module again in another context, with other arguments. So in this case the snippet is used when the code needs to be repeated.
Not repeated snippets?
Now to my question. Let’s say I’m in a template file, a long one. I have my snippets like
footer. The rest is not repeated and will not be used in another template.
Is it beneficial to use the snippets for stuff that only will happen one time, ever? In this case because the template is a long one?
I can’t make up my mind. How do you do it? Do you have snippets that are only used once?
For long pages/templates that contain multiple sections or different types of elements, I generally break things down into handy modules (snippets) even though the module may be used in a single template only.
In my opinion it is a lot easier to modify or work on single elements of a template this way. I just navigate to
snippets/module-a/subitem.php instead of scrolling through the massive template file to find the line I want to edit.
Me too, I tend to break things up rather than having long templates. Also, although I may be using a snippet only once in a site, some of those snippets may be reusable in other sites, so putting stuff into snippets makes sense.
I’ve started to break things up and now my current snippet structure looks a little bit like this:
Actually I have never considered to group snippets using subdirectories. Great solution!