Legacy Documentation
You are using the documentation for version 4.3.8. Go here for the latest version.
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, Template Partials, 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, 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.
Note
As of 2.9.0 conditional tags evaluate when ready.
Rendering Stages¶
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):
- {freelancer_version}
- Template partials
- MSM variables: {site_id}, {site_label}, {site_shortname}
- {last_segment}
- Member variables
- Parse 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 advanced 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
- Process template layouts
- Process embedded templates
- Process redirect variable
- Parse template-variables
- 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}
- {password_max_length}
- {theme_folder_url}
- {member_profile_link}
- {captcha}
- Add CSRF tokens to forms and parse {csrf_token}
- 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}
- Parse path variables (including {route=…} paths)