Have on mind that this post comes from someone who still after very few projects in EE is still a newcomer. That being said I’m looking forward to start a new project with a “best practice” approach. So, after listening and learning so much from the “unofficial” podcast with @lealea and @emilylewis (hopefully @mediagirl becomes part of the show) I’m in this anti-embed situation:

For I what I heard and read, {embeds} are not the best approach since they use many resources. But still I find no alarm or recommendation from EllisLab on how NOT to use them. The community via #eecms has shared some insights @Boyink tells me “try embeds and measure performance yourself. They still work fine in most cases.” @jasonleelab recommends Low Variables and @pauloelias goes for a Stash approach.

I thought about using Template Morsels and tried Stash Embed with very bad results: pages wont refresh and it was a design nightmare. (I did tried https://github.com/croxton/Stash/blob/dev/docs/working_with_files.md approach and I’m sure I’m doing something wrong).

I’m trying to find the best DRY method that doesn’t affect the site’s performance. At this point I have some HTML code that I want to use on several templates, a couple of {exp:channel:categories channel="Publicaciones" style="nested"} , etc. But I’m heading to a user site with lots of sessions and downloads and really wish to start the best way.

Any ideas? Thanks!

3 Answers 3


Have you considered using snippets?

Snippets can be considered to actually be part of the template that they are used on, with their expanded contents parsed simultaneous to other tags and variables on the template. Embedded templates are separate templates, with their own preferences (caching, PHP parsing, access, etc.), and are parsed individually. Put another way, embedded templates are not included in the parent template, but rather added to them after the fact, using a separate query and full page parsing resources for each template.

Snippets tend to be more performance friendly. Boyink talks about snippets on train-ee as well including some performance tests.


Stash is...hard to grok. The new docs are much better then the old:

https://github.com/croxton/Stash/wiki ..but still hardly a 'beginners guide'.

I found this the best of the simpler guides: http://pixelfear.com/blog/stash-workflow

...and I am a LONG way from an expert....but here's my 2c:

Basically, this is a structure for setting up a router -> data model -> visual template approach. It's pretty simple once you try it. You don't necessarily need to use the routing approach, but the basic idea of it is to nicely separate your getting & processing of the data from your channel(s) - and then the display of this data. I've taken it a step further and broken my display side of things into very modular chunks (I call them stash chunks but I actually store them as early parsed low variables, which are the same as snippets but I can group them and work with them on disk...).

Anyway - basically it goes like this:

Routing template: Grab any data you need initially and stash set it (e.g. list of categories). Then your routing template parses the URL (switchee, low seg2cat & using any data grabbed in the initial step) and directs the request to the appropriate model (stash:embed:my_model).

Model: The model grabs all the required data (exp:channel:entries or exp:low_reorder etc) - and stash sets it (as single stash sets or lists). You can have different models pulling from different channels, but setting the same stash data (meaning you can use the same chunks in your view/display template that will accept this data - neatly getting around the 'different but similar channels can't share the same fields with the same name issue that is mind numbingly dumb about EE).

The model also stash embeds a 'view template' (and can do so conditionally based on the retrieved data, for example - so you can vary your actual display template based on what your data model retrieved.)

View/Layout: Your view is basically html/css wrapped around a bunch of stash gets/get_lists. As I said, you can chunk this in to highly repeatable little blocks (stored as snippets/low vars). So you can then build you actual pages out of these re-usable modular blocks that receive the injected data.

Initially, avoid all caching stuff. That's what I have done - I suspect that's why your pages won't refresh..I havent even tried it yet but it will certainly complicate things initilly.

This approach makes the data grabbing stuff really easy and avoids a LOT of the parse order crap. It's pretty much a classic MVC approach....and very very DRY. Indeed if you go too crazy with chunking, it can be almost too DRY!

Anyway, @jason_varga explains it better.

Stash really is pretty awesome and it can probably do what you want...it's jsut hard to get initially and could do with some basic 'if you want to do this -> do this' type guides.


Your best approach is to choose the right tool and just use addons if you really need them. Stash, for example, allow you to do really crazy things and it can improve or decrease your performance, like any tool.

For static code, use User-defined variables. They are just added to your templates after all dynamic parsing (number 21 on parsing order).

For repeatable pieces of code, use snippets. They are added to your code before the modules and addons do its job (number 5 on parsing order).

Snippets and User-defined global variables can be edited as plain files using SnippetsSync. Just remember to disable the automatic update on your live site adding this code to your config.php:

$config['snippetssync_production_mode_override'] = TRUE;

Embeds are full templates that are added to its parents close to the end of parsing (number 19 on parsing order. They are your last option before addons.

For really little pieces of code you need on early stages of parsing, add them to your config file.

global $assign_to_config;
if( ! isset($assign_to_config['global_vars']))
$assign_to_config['global_vars'] = array(
    'cv-static_domain' => '//a.do.main',
    'cv-short_domain' => 'http://do.main'

Config variables can be accessed on templates just like snippets and are parsed before all modules and add-ons.

  • Think you missed a ' after short_domain ; ) Nov 15, 2013 at 5:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.