Hot answers tagged

34

For me, one of the most compelling reasons to use a "template partials" approach in EE (or model-view-viewModel - MVVM - if you prefer) is being able to separate out the presentation of your data (e.g. the html markup) from the business and model logic that retrieves and formats the data (the template tags, conditionals, data formatting and so on). This ...


17

Since the question is quite broad I'll try to summarise the advantages of the template partials pattern in general and Stash embeds in particular. Template partials allows code to be encapsulated into reusable chunks, to help you respect the DRY principle allows markup (the 'view') to be separated from the code that retrieves and formats your data (the '...


15

$assign_to_config is an EE-native array used in the index.php file. Here's part of the comments EllisLab left for us to provide context: The $assign_to_config array below will be passed dynamically to the config class. This allows you to set custom config items or override any default config values found in the config.php file. This can be handy ...


13

Here is the basic concept. I personally don't use the list tags to set a ton of individual variables. I find that it's too much and too tedious, and can perform an excess amount of queries if you have a lot of variables. I guess though it really goes down to how you prefer to organize your templates. {exp:channel:entries} {stash:embed:your_context:...


13

You'll probably need to show more of your template code but where Stash could benefit you is that you could use a single channel entries tag to output both the single entry view data and the recent blog posts at the same time. Here's a good example from Mark Croxton which shows how he approaches a similar thing.


13

Stash and Low Variables are complementary. Low Variables Essentially a replacement for native snippets and global variables. Provides a control panel interface for managing variables. Variables may be considered content - text values, matrix data, default images - or code, such as a tag that outputs your primary navigation or contains your footer markup. ...


12

You should be able to implement redirects once you add the Stash no_results_prefix parameter. For example: //Collect all values for all custom fields {exp:stash:set parse_tags="yes" trim="yes" parse_conditionals="yes" no_results_prefix="equipment"} {exp:channel:entries channel="equipment" url_title="{segment_3}" require_entry="yes"} {if equipment:...


11

Using the new var_prefix (came in in version 4.2 IICRC) embeds have / can been done away with. Links to docs - http://pixelandtonic.com/playa/docs/templates Example code: {exp:playa:children channel="news" parse="inward" var_prefix="news"} {news:exp:playa:children channel="editors" var_prefix="editor"} {news:title} - {editor:title} {/news:...


10

You can use the {exp:stash:destroy} {or it's alias {exp:stash:unset}) to unset a cached variable or variables within an entire scope (user or site): https://github.com/croxton/Stash/tree/dev#expstashunset-requires-php-523-or-expstashdestroy Here's an example of use to clear cached comments when a new comment is submitted: https://gist.github.com/3973821 ...


10

It's hard to tell what you're trying to achieve with Stash in that code sample. Since you are both 'setting' and 'getting' in the same place you aren't benefiting from a separation of markup and data, and as you're not using any caching you won't see any performance benefits either. Here's a quick example that would add caching for subsequent requests: {...


10

"I am using Stash only recently and was wondering how the performance is boosted over using embeds? I know there are a few less queries used in general, and I know you can subvert the parse order, but is there better reason to use it in templates?" Those were some of my own questions and with a couple of podcast from Lea Alcantara and Emily Lewis I got them ...


7

Stash doesn't parse preload_replace. But they will work if you use process="start" with the stash embed, since that effectively includes the sub template code in the host template prior to preload_replace being parsed by EE. However, be aware that if you need to access stash vars captured in the host template then you need to use process="end" (the default) ...


7

Tom is right that performance will be a problem regardless of how you approach this, so what you could do is cache the list of entries and related contributers. {!-- set the entries into a list, since we need to iterate over it twice. Prefix with 'p' to identify the 'parent' --} {exp:stash:set_list name="blog_entries" parse_tags="yes" scope="...


7

More often than not I usually put Stash on the outside of a channel entries tag, which should get around your issue, eg: {exp:stash:set parse_tags="yes"} {exp:channel:entries limit="1"} {stash:title}{title}{/stash:title} {/exp:channel:entries} {/exp:stash:set} {!--Now you can access like this in an embedded template or later in the parse ...


7

Try my answer on this question - works for me on a single template: EE Code within channel entries {exp:stash:set name="shortcode_inside_field" type="snippet"} <p>Hi there! It's important to set type="snippet" so that {shortcode_inside_field} will get automatically replaced with this sentence by the stash:parse tag later on.</p> ... now ...


7

The problem with that is that if {parent_id} doesn't get replaced with a number before the conditional is evaluated, then EE will choke because when converted to PHP it becomes: if ({parent_id} == 0) Either this {if parent_id != 0} Or this {if "{parent_id}" != "0"} Is more fault tolerant when the variable doesn't exist. But, you may wonder, why is ...


6

The performance gains are not just about using fewer embeds, they're equally about using fewer channel:entries tags, which are expensive. Your example is obviously not a complete web page, but if it were, how would you set the page's title and meta data and any other dynamic stuff that belongs in the <head>? How would you send related dynamic content ...


6

The initial code block could be made more efficient by wrapping the outer list around Channel Entries tag pair and the nested {exp:stash:set_list} around the Matrix variable pair instead of using {exp:stash:append_list} inside it (which creates multiple append_list tags). You can also create an explicit relationship between the outer and inner list by either ...


6

The important part is "later in the parse order". Are you trying to use the get within the same template as the set? If you are, you may have to add a priority parameter. I've had the best luck separating them entirely - by using a single embed as a wrapper template. So in my "about" template, I have nothing but channel logic and my "set" to stash the ...


6

After some help from the wonderful Mr. Croxton I was able to sort it out. Here is how to pull this off. When grabbing the data in your model you need to stash the {entry_id} of the parent list (I call mine {e_id} for no real reason). Then, when setting the nested list, provide context with the {entry_id} by using name="employees_{entry_id}". {exp:stash:...


5

As you say, automatic cache breaking is very nice, and IMHO a must, since anything else is bound to impact the user experience for the editors. My goto caching addon since its release has been CE Cache, which solves this nicely. For my 4–5 latest projects I've used the Template Partials approach (with Stash) increasingly. I love this way to develop in ...


5

Sounds like a great idea to me. I've added it to the issue list: https://github.com/croxton/Stash/issues/31


5

Stash won't parse EE embeds at all (this is by design) so you'll need to use a Stash embed instead. When you use process="end" the tag is replaced with a marker and 'post-processed' after the EE parser has completed parsing, and then replaced into the final template output. Therefore, it is up to the post-processed tag to do any parsing that might be ...


5

You could use the pagination segment as a context for your stashed variables. Each page of results would then be cached independently. The challenge with this approach is clearing the cache once any one of those cached pages expires (since the entire resultset may have changed since last cache). {exp:stash:context name="{segment_3}"} {exp:stash:set_list ...


5

A stash list is simply a serialized variable. Setting and getting a list is the same process as setting/getting a single variable, except the list has some additional processing to separate out the elements, serialize/unserialize, sort and paginate. In practice if you are not saving the variables with save="yes" then there is little appreciable difference in ...


5

After much searching and head scratching I finally turned to Twitter and got help from the fabulous @mediagirl and @low. The solution to this is fairly simple: To trigger a 'no_results' situation in the channel_entries loop using the entry_id parameter we have to enter either "-1" or "0|": entry_id = "0|" In my case I used "0|" and actually fixed_order ...


5

Personally, I tend to use separate templates and then do: {embed="_layouts/.two-column"} {snippet_common_page_elements} {!-- Unique page code goes here --}


5

Files are written to the static cache directory by Stash - you don't put files in there. Typically these cached files would be your fully rendered HTML pages. This is the opposite of the stash template directory, where you add template files (containing EE tags, variables etc.) which are read by Stash. After creating a folder called 'static_cache' (or ...


5

The reason you do not have access to that variable outside the loop is because your stash tags (getters and setters) are not parsed at the same time. EE module tags are parsed recursively from the outwards inwards, peeling them one after another like a oignon. In your code above, your stash set tags are inside an entry loop (level 2), while your get tag is ...


5

You have an extraneous single quote ' in each of your opening tag pairs. {stash:ee_img_original_width'}{width_orig}{/stash:ee_img_original_width} Should be: {stash:ee_img_original_width}{width_orig}{/stash:ee_img_original_width}


Only top voted, non community-wiki answers of a minimum length are eligible