ExpressionEngine Parse Order

In what order does EE parse variables and tags in its templates?

  1. Read URI, pick template (via an intelligent and complex process)
  2. Get template info, check permissions & authentication
  3. Get templateA (from file if exists) Hook Here: template_fetch_template
  4. “Static” templates are served “as-is”; ditto for templates that EE knows COULD be static... very efficient!

Quick Reference Guide

Order Tag Description

1

{logged_in_*} {template_*}D

{is_*_request} {site_*}

{last_segment} {current_url}

{current_path} {current_query_string}

{webmaster_path}

site variables (template partials, global_vars)ABC

2

{if in_group()}

conditionals

3

{segment_*}

segment variables

4

{segment:* }

template route segment variables

5

{embed:}

variables (only if template is called as an embed)

6

{layout:}

variables (only if it is called by a layout tag)

7

{errors}{/errors}

error conditionals

8

{current_time format="{DATE_ATOM}"}

date string constants

9

{template_edit_date}

{current_time}

{variable_time}

date variables

10

{consent:}

consent variables

11

Caching...

If template is cached, skip ahead to #18

12

<?php ?>

on input

13

{if ...}{/if}

conditionals (if variables are available)F

14

{preload_replace:}

preload replace variables

15

{exp:}

extension tags - outer before innerAFGHIJ

16

<?php ?>

on output

17

Caching...

if needed, write the mostly parsed template to cache

18

{if ...}{/if}

Conditionals (all remaining)FK

19

{layout=}

process the associated template (this starts a new loop)

20

{embed=}

tags - process all (each embed starts a new loop)

21

{layout:}

Clean up unused tags. Hook here: template_post_parse

22

{redirect=}

Trigger the first remaining tagJL

23

site and global

template variables (no conditionals allowed here)M

24

{stylesheet=} {encode=}

{path=} {route=}

tag processing

25

CSRF

Add security hashes and ACT IDs

26

HTML output cleanup

Remove any lingering EE commentsA

Notes

  1. Any EE comments are removed at this step
  2. 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.
  3. global_vars ≠ Global Template Variables i.e. there’s overlap but the two are not exactly the same
  4. But not {template_edit_date} because it might need to be date formatted by step 8
  5. It’s unclear how {if in_group()} works with “roles”
  6. Conditionals will get parsed here if all their variables exist
  7. Plugins parse inside to outside unless you use parse=”inward”
  8. {exp:} tags in the parameters of another tag get parsed first in most cases
  9. {search:} tags on any search results page can also be used as a parameter of an {exp:} tag
  10. {redirect=} in any triggered {if no_results} tag pair fires immediately when it is parsed
  11. This step is still called “advanced conditionals” in the code, but it is not just those specifically
  12. 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?
  13. 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