Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

None reusable snippets?

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

like image 700
user1070143 Avatar asked Nov 07 '12 09:11

user1070143


2 Answers

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.

  • Template Partials using Stash
  • Homegrown plugin to create template “partials” for ExpressionEngine
like image 177
pvledoux Avatar answered Oct 29 '22 03:10

pvledoux


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

like image 32
Samsull Avatar answered Oct 29 '22 05:10

Samsull