Snippet workflow?

Repeated snippets

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 header and 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/modula-a/module-a.php or snippets/module-a/subitem.php instead of scrolling through the massive template file to find the line I want to edit.

1 Like

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.

1 Like

I’ve started to break things up and now my current snippet structure looks a little bit like this:

- snippets
    - globals
        header.php
        footer.php
    - pages
        - about
            snippet1.php
            snippet2.php
        - contact
            snippet1.php
            snippet2.php
            snippet3.php
- templates
3 Likes

Actually I have never considered to group snippets using subdirectories. Great solution!