Parse Order in
ExpressionEngine’s Templates
But First...
Introduction:
Who am I?
Rowan Sentesy
Self-taught (mostly)
~12 years EE experience
Entrepreneur
Freelance
Now: developer with Hop Studios
Introduction: Overview
What we’re going to talk about:
EE Templating
What is Parse Order?
{stuff} => <html>..</html>
Parse & Render
Tags are rendered, can be used later in the process.
Order is important
Let’s see what EE has to say...
Can we change parse order?
Yes … Kind-of …
Example 1 - Default (Outward)
<h1>Default (outward)</h1>
{exp:rss_parser url="https://ellislab.com/blog/rss-feed" limit="5"}
<ul>
{feed_items}
<li><a href="{item_link}">{item_title}</a><br />
{exp:word_limit total="35"}
{item_content}
{/exp:word_limit}
</li>
{/feed_items}
</ul>
{/exp:rss_parser}
Example 2 - Inward
<h1>Inward</h1>
{exp:rss_parser url="https://ellislab.com/blog/rss-feed" limit="5" parse="inward" }
<ul>
{feed_items}
<li><a href="{item_link}">{item_title}</a><br />
{exp:word_limit total="35"}
{item_content}
{/exp:word_limit}
</li>
{/feed_items}
</ul>
{/exp:rss_parser}
Example 3 (bonus)
<h1>Outward with :limit</h1>
{exp:rss_parser url="https://ellislab.com/blog/rss-feed" limit="5"}
<ul>
{feed_items}
<li><a href="{item_link}">{item_title}</a><br />
{item_content:limit characters="210"}
</li>
{/feed_items}
</ul>
{/exp:rss_parser}
Extension Hook Priority
Two hooks for template parsing:
priority - an extension hook could have many extensions being called, so there needs to be priority. 1 => First, 10 => common default, 99+ => Last.
Think: z-index for timing.
The Big Ones �(my list)
Thanks to Low
Kudos to @Low for this EE 2 Parse order document!
Back in 2010, Low created this document.
Lodewijk Schutte (aka @Low)
Introducing the …
EE Parse Order
Quick Reference Guide
Common problems with Parse Order
Variable name collision was a problem when nesting {exp:}tag pairs!
Over the years this has become less of an issue, thanks to prefixing!
Prefixing: A Quick look
Generally, this works very well.
It is rare to encounter issues with this since Relationships & Grid were introduced by EE.
Use PHP in templates
Don’t do it!
Do it!
PHP not in EE (without add-on)
PHP to provide info about
Example: file directory listing
PHP Parse Stage
Parse stage: Input
Do some PHP feed results into EE module.
<?php
/* Set an array */
$entry_ids = [1,2,3,4,5];
?>
<!-- Use an array -->
{exp:channel:entries entry_id="<?=implode("|",$entry_ids)?>"}
<h1>{title}</h1>
{/exp:channel:entries}
Parse stage: Output
Use EE module to build php variable/array.
<?php
$data = [];
?>
{exp:channel:entries limit="100"}
<?php
$data[] = [{entry_id},'{title}'];
?>
{/exp:channel:entries}
<?php
echo "<pre>";
print_r($data);
echo "</pre>";
?>
Problem:
List & Total
Consider this example
How would you solve for…�Price total (numeric)�Emails (list)
Type it in the chat.
Try without PHP
(First try)
Requires: Stash, MX Calc
Try without PHP�(Second try)
Requires: Embed, Stash, Tally
Try with PHP
Requires: PHP (output)
List & Total: Conclusions
Which do you like the best?
But First...
Summary
Q&A
Ask in the Q&A tab,
or follow the instructions provided by EE Conference team...
Thank you!
Thanks to the EE Team: �Tom, Brian, Andy (and others!)
Reach out:�rowan@hopstudios.com
EE Slack:�@Rowan Sentesy
Twitter:�@hopstudios
Parse Order PDF: