The Template Engine
When ExpressionEngine serves up each Template, the system must go through a rendering process to parse out the Tags, Variables, Template Partials, and Embeds being used in the Template. This page explains the order of those rendering stages. This information can be immensely useful when building pages and troubleshooting problems.
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, or the Discussion Forum module.
Rendering Order
The Template Engine processes the selected template fully from top to bottom through each rendering stage.
- Determine template to process based on request URI
- Get template from database, check template access permissions, and increment the hit counter
- If it exists, get template from file
- If template type is static, return template and end parsing
- Parse (as a group, so order is irrelevant):
- Template partials
- MSM variables: {site_id}, {site_label}, {site_shortname}, {site_name}, {site_url}, {site_description}, {site_index}
- {last_segment}
- Member variables
- {webmaster_email}, {current_url}, {current_path}, {current_query_string}
- {template_name}, {template_group}, {template_group_id}, {template_id}, {template_type}
- {is_ajax_request}, {is_live_preview_request}
- Parse {in_group()} and segment variables
- Parse embed variables
- Parse layout variables
- Parse date formatting string constants
- Parse {template_edit_date}
- Parse {current_time}
- If present, get cached template, then skip to the second conditionals parsing stage
- Parse PHP on Input
- Parse conditional tags
- Assign and parse preload_replace variables
- Parse module and plugin tags
- See notes on how nested plugins are parsed.
- If any module’s {if no_results} tag pair evaluates true, a {redirect} variable within the tag pair will be processed immediately.
- Parse PHP on Output
- Write template to cache file
- Parse conditional tags a second time to catch conditionals for variables and forms that shouldn’t get cached
- Process template layouts {layout=}
- Process embedded templates {embed=}
- Process the first remaining {redirect=} tag
- Parse Site Template Variables and Global Template Variables again, all at once, including:
- {app_build}
- {app_version}
- {build}
- {charset}
- {cp_session_id}
- {cp_url}
- {current_path}
- {current_query_string}
- {current_url}
- {debug_mode}
- {doc_url}
- {email}
- {group_description}
- {group_id}
- {group_title}
- {gzip_mode}
- {hits}
- {homepage}
- {ip_address}
- {ip_hostname}
- {is_ajax_request}
- {lang}
- {last_segment}
- {member_group}
- {member_id}
- {member_profile_link}
- {password_max_length}
- {private_messages}
- {screen_name}
- {site_description}
- {site_id}
- {site_index}
- {site_label}
- {site_name}
- {site_short_name}
- {site_url}
- {template_group_id}
- {template_group}
- {template_id}
- {template_name}
- {template_type}
- {theme_folder_url}
- {theme_user_folder_url}
- {total_comments}
- {total_entries}
- {total_forum_posts}
- {total_forum_replies}
- {total_forum_topics}
- {username_max_length}
- {username}
- {version_identifier}
- {version}
- {webmaster_email}
- Process {stylesheet=} / {scripts=} / {encode=} / {path=} / {route=} tags and variables
- Add CSRF tokens to forms and parse {csrf_token}