7

I'm using snippets to break up long templates into more manageable chunks, is this bad practice and should I only use snippets for reusable code?

Thanks Lee

user1070143
  • 427
  • 2
  • 5

2 Answers2

5

It depends of what you are doing in your templates. It is indeed generally a good practice to reuse part of templates in smaller chunks, but it's recommended to avoid the usage of embeds because of underlying performance issues. Snippet are cool as soon as you don't have to pass variables to your sub-templates.

Maybe a good approach for you if your templates are not already totally coded is to use the 'template partial' technique. See the following tutorials here under.

pvledoux
  • 973
  • 1
  • 10
  • 23
3

You should look at using an add-on, I use either Low Variables or Republic Variables (free), where you can store snippets and parse them early or late. They can also be saved as files which is handy.

You can find them on http://devot-ee.com

Samsull
  • 419
  • 2
  • 6
  • 1
    Have a look at Low's work here: http://gotolow.com/blog/snippets-and-preload-replace-variables that will help you understand how things work with snippets and why – Jelle Dijkstra Nov 07 '12 at 10:54