In what order does EE parse variables and tags in its templates?
- Read URI, pick template (via an intelligent and complex process)
- Get template info, check permissions & authentication
- Get templateA (from file if exists) Hook Here: template_fetch_template
- “Static” templates are served “as-is”; ditto for templates that EE knows COULD be static... very efficient!
Quick Reference Guide
Order | Tag | Description |
---|---|---|
1 |
|
site variables (template partials, global_vars)ABC |
2 |
|
conditionals |
3 |
|
segment variables |
4 |
|
template route segment variables |
5 |
|
variables (only if template is called as an embed) |
6 |
|
variables (only if it is called by a layout tag) |
7 |
|
error conditionals |
8 |
|
date string constants |
9 |
|
date variables |
10 |
|
consent variables |
11 |
Caching... |
If template is cached, skip ahead to #18 |
12 |
|
on input |
13 |
|
conditionals (if variables are available)F |
14 |
|
preload replace variables |
15 |
|
extension tags - outer before innerAFGHIJ |
16 |
|
on output |
17 |
Caching... |
if needed, write the mostly parsed template to cache |
18 |
|
Conditionals (all remaining)FK |
19 |
|
process the associated template (this starts a new loop) |
20 |
|
tags - process all (each embed starts a new loop) |
21 |
|
Clean up unused tags. Hook here: template_post_parse |
22 |
|
Trigger the first remaining tagJL |
23 |
|
template variables (no conditionals allowed here)M |
24 |
|
tag processing |
25 |
CSRF |
Add security hashes and ACT IDs |
26 |
HTML output cleanup |
Remove any lingering EE commentsA |
Notes
- Any EE comments are removed at this step
- Template Partials (aka snippets aka global_vars) will override variables with matching names, but everything is parsed at once, meaning one variable’s output that contains the name of another will not parse
TL;DR: You can’t nest Template Partials. - global_vars ≠ Global Template Variables i.e. there’s overlap but the two are not exactly the same
- But not
{template_edit_date}
because it might need to be date formatted by step 8 - It’s unclear how
{if in_group()}
works with “roles” - Conditionals will get parsed here if all their variables exist
- Plugins parse inside to outside unless you use parse=”inward”
{exp:}
tags in the parameters of another tag get parsed first in most cases{search:}
tags on any search results page can also be used as a parameter of an{exp:}
tag{redirect=}
in any triggered{if no_results}
tag pair fires immediately when it is parsed- This step is still called “advanced conditionals” in the code, but it is not just those specifically
- We would prefer to redirect before parsing all sub-templates, but we are sure there is a reason. Maybe so that you can redirect from an embed that is positioned in the main template ahead of another redirect?
- This step now includes parsing the output of entry fields, which can mean variations in final output from earlier versions of EE
Version 1.0.1 (2021/04/28), based on EE v6.0.3 /system/ee/legacy/libraries/Template.php
ExpressionEngine Parse Order prepared by Travis Smith & Rowan Sentesy of Hop Studios (@hopstudios) for #EECONF2021