Home > snippets > Is there a way to change the parse order of snippets or plugins?

Is there a way to change the parse order of snippets or plugins?

February 7Hits:1
Advertisement

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

Answers

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

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.

Tags:snippets

Related Articles

  • Is there a way to change the parse order of snippets or plugins?February 7

    Is there a way to force snippets or plugins to be parsed late or at least after advanced conditionals are parsed? --------------Solutions------------- There are plenty of plugins to mess with the parse order, but I usually try to avoid installing plu

  • Wrong PHP parsing order in snippetSeptember 9

    I'm trying to parse a global variable inside a snippet that represents my page footer, and I want to perform a string function on the content of that variable. The snippet is being called into a template with PHP parsing ON and set to OUTPUT. This is

  • Low Variables with Switchee - parse order issueFebruary 4

    Hi I'm having a parse order issue that I can't seem to figure out. I have a template that looks like this: some code here <div class="content-line"> {exp:low_variables:parse var="lv-inner-content" preparse:transcribe:language_abb

  • Embedded variables conditional - Assets 2 Issue or parse order?April 16

    I am having an issue with an embedded template. I embed the template passing a "type" variable. Then, in the embed file it displays the content based on which "type" was specified. This all works, but either the parse order or Assets i

  • Stash + Matrix Parse Order?June 4

    The following code works if I comment out the Matrix fields (images {stash:st_{pre_channel}_image_url}). However, I can't get the code working with the image tags back in. I'm guessing it's a parse order issues :-/ I've tried everything I can think o

  • Advanced conditional & Low Variable parse orderAugust 5

    I need to use an advanced conditional with Low Variables and am having trouble getting it to work. I believe it's a parse order thing but am not sure how to get around it. I am checking the current date/time against 2 Low Variables to see if the curr

  • Parse Order 2.6.1 and SafeCrackerSeptember 30

    I recently upgraded to 2.6.1 and I am running into an issue that seems like it could be parse order related, I have the following code that was working before the upgrade. {if segment_3=="summary"} {exp:safecracker channel="jobs" retur

  • How to outsmart ExpressionEngine Parse Order?January 29

    I need to get this work - how can I code this to get the parse-order I need? {exp:channel:entries channel='{exp:plugin entry_id="{segment_3}"}' - As you can see in the code above: I read out the 3rd segment of the url, paste it in a attr of a pl

  • It is possible to parse an ExpressionEngine snippet inside a page via Ajax?March 29

    It is possible to parse an ExpressionEngine snippet inside a page via Ajax ? like: {exp:channel:entries channel="news" limit="10"} <h2>{title}</h2> {body} {/exp:channel:entries} The EE code would be processed and returned a

  • Stash & Switchee parse order problemsOctober 9

    I have the following blocks of code that I can't seem to to work correctly. The list sets and populates perfectly, but the switchee statement doesn't work. I konw that it has do do with parse order but I can't figure out what is going on. The debug v

  • Parse order questionNovember 18

    I have a fairly complicated sequence of queries that I need run in order as later queries rely on results from a previous query and I'm using PHP to help refine and save data. I need to pass in a PHP value into two of my EE queries but I can't get a

  • Set Stash variable in Channel entry loop, then use in email contact form? Parse order issues?April 1

    The following is part of an embedded template, which is passed {embed:advertisers_entry_id} that contains a string like 34|68|124|: {!-- Set defaults --} {exp:stash:recipients}{/exp:stash:recipients} {exp:stash:user_recipients}no{/exp:stash:user_reci

  • Parsing post- ID in included plugin fileApril 12

    running into something that has got me completely puzzled. I have a plugin with a main file that looks like this: // Global Variables $mouldings_prefix = 'mouldings_'; $mouldings_name = 'Mouldings'; if(!defined('MOULDINGS_BASE_DIR')) { define('MOULDI

  • parse order and nested conditionalsMarch 6

    Can i nest simple conditionals and are nested simple conditionals still parsed early? What happens when nesting an advanced conditional inside a simple conditional? (wiki answer) --------------Solutions------------- the following template will genera

  • Stash: How can I preset a channel var in the right stage of the parse order?March 15

    I'm trying to use Stash embeds on a pretty complex site and can 'see' a way to make things more DRY but can't actually figure out how to 'do'. I have a collection of viewModal templates, that handle the various channels, and a lot of these channels s

  • Parse Order and Redirect=April 5

    I know I have come across this before but the solution is escaping me. I have a template and a channel lets call it widgets. If I go to the URL /widgets/ I want it to show all the entries of channel="widget" no problem. Now if i have a url of wi

  • Problems with CE Image, MX Jumper and parse order (I believe)August 8

    I'm experiencing two possible issues in the code below: The if/else I have always sets standard_image_width and retina_image_width to the value in the last {if:else}, regardless of whether or not it's correct; and Whatever that value turns out to be

  • Parse order for Stash? - stashing an entry_id and retrieving it again laterDecember 13

    I'm using EE 2.7.2 with Stash 2.4.7. I'm attempting to stash an entry_id and then retrieve it again elsewhere on the page. I've got a site with two important channels - people and awards. On each award, I've got a relationship field (award_winner) th

  • Channel Entries - Author Id Parse orderMarch 13

    I have this code here {exp:channel:entries author_id="1|CURRENT_USER" channel="foo" disable="categories|category_fields|member_data|pagination" dynamic="no" orderby="entry_id" sort="asc" parse=&q

  • Parse order problem with CE Image?June 17

    {exp:ce_img:single allow_scale_larger="yes" crop="yes|center,center|0,0|yes" filter="auto_sharpen" hash_filename="yes" height="{embed:height}" parse="inward" src="{exp:stash:get name='defaul

Copyright (C) 2017 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.741 s.