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?
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
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.