Take the 2-minute tour ×
ExpressionEngine® Answers is a question and answer site for administrators, end users, developers and designers for ExpressionEngine® CMS. It's 100% free, no registration required.

This is a fairly straight forward question... Does preload_replace not work in stash:embed templates? In my embed templates, I tend to set a bunch of preload replace variables for things like channel name and custom field prefix so that if i ever have to change something, one change in the first couple of lines runs through the template and replaces al such instances. But when i try that in a stash:embed template, the preload replace items just render as plain text in the template. Is there a way to get them to work, or is this simply an unavoidable parse order issue?

share|improve this question
2  
I have had the same issue. I found a suitable workaround to be using Stash settings/getters in place of preload_replace, but this is not the answer to your question. –  Justin Kimbrell Dec 2 '12 at 19:43
    
So far, I've resorted to doing effectively the same thing by passing those same values within the stash:embed itself as variables. Not perfect, but it works. I'm finding it odd, however, that performance of the page in question is reduced at the moment compared to what it was using a native EE embed. –  Jean St-Amand Dec 2 '12 at 20:17
add comment

1 Answer 1

up vote 7 down vote accepted

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) due to parse order; also process="start" templates cannot be pre-rendered (parse_stage="set") since the EE parser is not initialised at the point the template is included.

This is off-topic but addresses your comment about performance above:

By default a Stash embed works in a similar way to an EE template, and you will not see a performance gain if you are just including one or two templates in a host template. If you nest your stash templates or use them multiple times then you will notice a gain. And if you 'tune' your embeds - by which I mean choose to pre-render and cache parts or the whole of your template and experiment with parse_depth, parse_vars etc - then you will see significant gains. You should also disable file sync ('stash_file_sync'=false) on your production environment.

The other significant advantage of a stash embed is that you can have multiple cached instances of the same template. That is possible because you can specify a file name separately from the variable name for the embed. This can be helpful for caching things like submenus which might share the same generation code but have different output for the various sections of your site.

share|improve this answer
    
Thanks Mark. I thought with stash embeds avoiding the full template parser they would see an uptick in performance, which is why I asked. I like your suggestion of the re-usability and portability aspect of the stashed embed - definitely helpful. –  Jean St-Amand Dec 3 '12 at 0:25
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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