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 ...


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

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. ...


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 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

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}


5

UPDATE: Got it working. This is what I have for those following: set_list template: {stash:embed:layouts:homepage} {exp:stash:context name="100_list"} {exp:stash:set_list name="movie_list" context="@" parse_tags="yes" save="yes" scope="site" refresh="1440" replace="no" } {exp:channel:entries channel="films" ...


5

{exp:stash:get name="foo"} is a module tag. When the template parser encounters it, it calls the get() method of the 'stash' module class, which returns the value of foo. If foo doesn't exist, an empty value is returned, unless the default="" parameter has been set. {exp:stash:foo} is a shorter syntax version of the above tag, for convenience. {stash:foo} ...


5

There's no sense in running channel entries twice. This code generates a bunch of stash capture pairs, mapping field names in different channels to a common name: {!-- make a list of your channel prefixes --} {exp:stash:set_list name="channels"} {stash:channel}article{/stash:channel} {stash:channel}book{/stash:channel} {stash:channel}project{/...


5

You can do this without a callback function: $config['resource_router'] = array( 'posts' => 'templates/index', 'posts/:category_url_title' => 'templates/cat_entries', 'posts/:category_url_title/:any' => 'templates/view', );


4

If I'm trying to get the stash in the same template I find using process=end in the stash:get usually works. {exp:channel:entries channel="work" limit="1"} Expected: {title} / {exp:stash:set name="title"}{title}{/exp:stash:set} {/exp:channel:entries} {!-- access with process="end" --} Result: {exp:stash:get name="title" process="end"} More info on process ...


4

You are running into a parse order issue. Here is a somewhat simplified version of what you did but another way to approach it: {exp:channel:entries channel="properties" dynamic="off" search:property-featured="=y" orderby="random"} {exp:stash:append name="big_images"} <li><img src="{big-image}" alt="{alt-text}"></li> {/exp:...


4

Ok, this is complex so please bear with me. Unlike process="inline" and process="end", the process="start" parameter is relative to the processing stage of the host EE template, not the processing of the nested Stash template (which is undertaken by a separate instance of the template parser and occurs either in parallel with or after the EE parser has run)....


4

There are two problems here. First, at the point you try to use dofoco-favorites it doesn't exist yet. Second, without using parse_tags="yes" when setting the list, the enclosed channel entries tag won't get parsed and the list won't be generated in order to be captured. I keep banging on about peeling onions, but it's a helpful metaphor when thinking about ...


4

Inverse Matching (?m)^((?!\bLight\b).)*$ You can see it in action here and take note of the info in the shot. Everything highlighted is being matched or in this case not matching Light: If you need to match both lowercase and capital light then you'd change it to this. Everything highlighted is being matched or in this case not matching Light or light: (?...


4

You'd be better off just 'stashing' the image urls and using the CE Image tag from within the layout. Article {f-archive-images} {exp:stash:set_list name="images"} {stash:url}{f-archive-images-image}{/stash:url} {/exp:stash:set_list} {/f-archive-images} Layout First image: {exp:stash:get_list name="images" limit="1"} {exp:ce_img:single src="{...


4

{exp:stash:static} caches the entire page to a static file. The cached output is not stored in the database. And you can't cache just a region / section of the page. When it works for you to use {exp:stash:static}, it should return pages noticeably faster than {exp:stash:cache}, and also (since the page requests route directly to the static file, without ...


4

Couldn't you just use a Snippet for this? It would contain the markup and code used inside a tag, which you could re-use with multiple tags. For example: {exp:low_search:results ... } {sn_entry_list} {/exp:low_search:results} {exp:channel:entries ... } {sn_entry_list} {/exp:channel:entries} An so on.


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