ExpressionEngine Docs

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 (legacy), or the Discussion Forum module.

Rendering Order

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):
    • 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}
  6. Parse {in_group()} and segment variables
  7. Parse embed variables
  8. Parse layout variables
  9. Parse date formatting string constants
  10. Parse {template_edit_date}
  11. Parse {current_time}
  12. If present, get cached template, then skip to the second conditionals parsing stage
  13. Parse PHP on Input
  14. Parse conditional tags
  15. Assign and parse preload_replace variables
  16. Parse module and plugin tags
  17. Parse PHP on Output
  18. Write template to cache file
  19. Parse conditional tags a second time to catch conditionals for variables and forms that shouldn’t get cached
  20. Process template layouts {layout=}
  21. Process embedded templates {embed=}
  22. Process the first remaining {redirect=} tag
  23. 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}
  24. Process {stylesheet=} / {scripts=} / {encode=} / {path=} / {route=} tags and variables
  25. Add CSRF tokens to forms and parse {csrf_token}