ExpressionEngine

2.5.5 User Guide

The Template Engine

At a basic level, Templates contain almost everything you want displayed on the front-end of the site. When ExpressionEngine serves up each Template, the system must go through a rendering process to parse out the Tags, Variables, Snippets, and Embeds being used in the Template.

Note

The information in this article applies only to rendering Templates. It doesn’t apply to rendering theme files such as those used for Member Profiles, the Wiki module, or the Discussion Forum module.

ExpressionEngine goes through several stages to fully process each Template, and this article exposes the order of those rendering stages. Understanding how the system renders a template can help immensely when building pages and troubleshooting problems.

The use of Conditional Variables provides a great example here. Simple conditionals are parsed before module tags, but advanced conditionals are parsed after module tags. If a simple conditional evaluates false, ExpressionEngine simply ignores a module tag within that conditional, neither rendering it nor displaying it. But if an advanced conditional evaluates false, ExpressionEngine can only hide the output of the already fully rendered module tag. That amounts to a big difference in performance.

Rendering Stages

The Template Engine processes the selected template fully from top to bottom through each rendering stage.

  1. Determine template to process based on request URI
  2. Get template from database, check template access permissions, and increment the hit counter
  3. If it exists, get template from file
  4. If template type is static, return template and end parsing
  5. Parse (as a group, so order is irrelevant):
  6. Parse segment variables
  7. Parse embed variables
  8. Parse date formatting string constants
  9. Parse {template_edit_date}
  10. Parse {current_time}
  11. If present, get cached template, then skip to the advanced conditionals parsing stage
  12. Parse PHP on Input
  13. Parse simple conditionals: segment, embed, global variables
  14. Assign and parse preload_replace variables
  15. Parse module and plugin tags
  16. Parse PHP on Output
  17. Write template to cache file
  18. Parse advanced conditionals
  19. Process embedded templates
  20. Process redirect variable
  21. Parse user-defined global variables
  22. Parse some standard global variables (separately, in order given):
    • {hits}
    • {ip_address}
    • {ip_hostname}
    • {homepage}
    • {cp_url}
    • {site_name}
    • {site_url}
    • {site_index}
    • {webmaster_email}
    • {stylesheet}
    • {encode}
    • {debug_mode}
    • {gzip_mode}
    • {app_version}
    • {version}
    • {app_build}
    • {build}
    • {charset}
    • {lang}
    • {doc_url}
    • {theme_folder_url}
    • {member_profile_link}
    • {captcha}
  23. Add security hashes to forms and parse {XID_HASH}
  24. Parse remaining standard global variables (separately, in order given):
    • {member_id}
    • {group_id}
    • {group_description}
    • {group_title}
    • {member_group}
    • {username}
    • {screen_name}
    • {email}
    • {ip_address}
    • {location}
    • {total_entries}
    • {total_comments}
    • {private_messages}
    • {total_forum_posts}
    • {total_forum_topics}
    • {total_forum_replies}
  25. Parse alternative syntax forms of the member variables above
  26. Parse path variables