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


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.


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


8

You can do this without editing the Wygwam source. First you need to create a custom config file for CKEditor. Create a JavaScript file called something like 'ckeditor_config.js' and then set Wygwam to use it. You can do this by adding an advanced setting to your Wygwam editor configuration. Add the 'customConfig' setting and enter the path to the JavaScript ...


7

If performance is only a problem when the site gets hit by a lot of traffic, you might want to turn on caching for that particular tag (I'm not really a fan of full page caching). That is what it is meant for... {exp:channel:entries cache='yes' refresh='60' ...} Might I ask why you have at all? You shouldn't need it since you are not nesting the same tags.....


6

You probably don't need to build your own plugin for this. If that logic is all you have to worry about then Switchee and a couple of regular expressions are all you need. {exp:switchee variable="{segment_1}" parse="inward"} {!-- Seg 1 = empty. Embed homepage template. --} {case value="''"} {embed="embeds/homepage"} {/case} {!-- ...


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

What if you created fields for each location's price for that menu item. Then the field name would be prefixed with the child site's short_name. atlanta_item_price chicago_item_price seattle_item_price Etc. Then in your child site template, you could use: Price: {{site_short_name}_item_price}


6

I would probably use a matrix in the main sites entry with two columns: location and price. One is location and one is price. Fill that in for each location. The location column would need to be a dropdown that the user selects the correct location. The dropdown would be set up so that the value is equal to the site name and the label to the Restaurant name. ...


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 should do this in an Extension instead - an extension on the sessions_end hook (which is called near the beginning of every request to the site, just after the Session library has finished loading). You could then create new Global Variables before any template parsing begins, and which would then be available to all of your templates. Extensions are ...


5

I recommend using SEO Lite. It will save you from having to open up a channel:entries tag just to grab the title. Plus it can be used for a meta description tag (which is also useful for og:description and social share text). And it has a variety of useful parameters to help you pull the right title and to add prefixes or suffixes to your title. Just ...


4

You could nest another conditional: {if total_results < 3} {if count==total_results} {embed="includes/homepage-properties"} {/if} {/if}


4

We use this code in our header embed; allows us to do something like {embed="site/_header" meta_title="Example Title"}; alternatively we can specify an entry ID, and SEO Lite will figure out the correct info, or, we can just let it rely on the last segment, which works 95% of the time. It's worth noting that we're also using Mark Croxton's IfElse add-on ...


4

A few embeds never hurt anyone, despite the hype! Yes they can have a performance hit on busy or content heavy/intensive sites but for smaller sites you'd probably barely even notice, save for a few extra queries on page load. You can always use Snippets instead of embeds if you want to segmentate your code into smaller chunks. Saying that, as you're only ...


4

This way is not possible because of ExpressionEngine’s Parse Order Parse advanced conditionals Process embedded templates With your code you don't have "yes" in conditionals when EE parses it, you have "{embed="test/foo"}"


4

As I told you earlier today, this is not a Low Search issue, but a conditionals parsing issue. If you turn on Template Debugging, you'll see the opening tag just before it is actually executed. It will look something like this: {exp:low_search:results {if embed:author_id}author_id=""{/if} ... } That is what's executed, and what EE uses to set the internal ...


3

The Template class allows you to work with template data from inside a plugin, but I don't think it lets you do it in the way you're suggesting. As far as I know, you can't directly ask a plugin to embed something, because it's working at a different level of the render stack than where you would normally call the {embed} tag. What you can do is use the ...


3

I agree that this is a parse order issue. It would probably be better for you to set your global variable in the config.php. Not only will this ensure it's set before the templates are parsed, but it'll also prevent you from needing to use PHP in your template, which makes things a bit more secure and efficient. If you're using the Focus Lab Master Config, ...


3

Another option that I have used in the past is with Playa: Create as many channels as you need modules (text, events, video, 1 big image, image gallery, etc.) and enter content Create a "page" channel with a playa field linking to your modules channels. Use conditionals / ifelse / switchee to test on the channel_short_name and display module fields: ...


3

Not natively I believe. I typically use Stash to do this nowadays. It will give you persistent variables as well as template inheritance so you can do things like this. Wrapper template <!DOCTYPE html> <!-- paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ --> <!--[if IE 7]><html class="no-js lt-ie9 lt-ie8" lang="...


3

I believe to do so, you would need to create a Custom Style Set for Wygwam. See the Wygwam Docs over a Pixel & Tonic. Though, I recommend creating a class instead of an id. Since someone will most likely add more than one media embed sometime in the future. Additionally, this StackExchange post deals with editing the Wygwam .js for custom sets.


3

Why not do it the other way around, where the template being loaded is what actually contains the complex logic? Then you can embed the rest of the template, passing the entry_id via an embed parameter. Alternately, write a simple plugin which performs your logic and returns the entry_id, then put your Channel Entries tag inside of that plugin tag pair (...


3

Stash 2.4.3 corrected a long-standing inconsistency with embeds set to process at the start of template parsing. At the other stages of parsing (inline and end) embeds are parsed by default - that is to say, parse="yes" is the default parameter value if not specified, and 2.4.3 added this as the default for start too. To make your embed behave as it did ...


3

Snippets are not intended to be used by / known by end users. They are developer tools for making your code more DRY - not so much to hold content. This is why the access to them is through the Templates area of the CP rather than the Content area. Here is one approach to allowing users to create different sidebars - note that you could use the native ...


2

Sorry to throw a cat amongst the pigeons but stash is very much a purist approach. Sure there are advantages of it but it takes a multi designed and structured site to a whole new level of complexity. For me and now... Low Variables will do for the performance hit of embeds.


2

I suspect it has something to do with the parse order of the tags. Could you try adding parse='inward' to your {exp:channel:entries} tag. You can check if it is embedding the values or the entire {exp:query} tag if you turn on template debugging and look at how the entries tag is parsed. – Wouter


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