3

Is there a way to force snippets or plugins to be parsed late or at least after advanced conditionals are parsed?

  • You can add parse="inward" to a plugin to parse the contents first. See: ellislab.com/expressionengine/user-guide/templates/plugins.html – fccotech Feb 7 '13 at 6:28
  • Can you explain what you want to achieve? the current question is very broad. In general, no, snippets are like "copy-paste" data that are replaced very early on in the template. If what you want to do is more clear, there might be other solutions. – GDmac Feb 7 '13 at 10:57
  • @GDmac Basically, my problem is that some tags in the snippets are not parsed because they or parse order problems. This causes problems where the actual tag string literal i.e. '{foo}' is being passed. – developarvin Feb 8 '13 at 2:27
  • which tags are not parsed inside your snippets? – GDmac Feb 11 '13 at 13:59
4

There are plenty of plugins to mess with the parse order, but I usually try to avoid installing plugins if I can help it.

The simplest solution, which works in 99% of cases, is to just use an embed. Embeds are parsed after everything else, so whenever you have an early parsing issue, just throw the problem code into an embed.

It's true that embeds have slightly worse performance, but most people worry about this way too soon. Don't optimize for performance until performance is a problem. YAGNI.

Before:

{exp:channel:entries}
    {exp:annoying_plugin parameter="{entry_id}"}
{/exp:channel:entries}

After:

{exp:channel:entries}
    {embed="partials/.my_embed" entry_id="{entry_id}"}
{/exp:channel:entries}

Inside partials/.my_embed:

{exp:annoying_plugin entry_id="{embed:entry_id}"}
| improve this answer | |
1

You can use Stash to delay the parsing of an arbitrary group of tags until after template parsing has completed:

{exp:stash:parse process="end"}
   {exp:channel:entries}
       ...
   {/exp:channel:entries}
{/exp:stash:parse}

However, parse order issues generally arise when you need to pass values generated by one tag to another tag or position somewhere else in your template. Adopting the template partials pattern can help you avoid these parse order problems in the first place.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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