2.11.7 User Guide

Legacy Documentation

You are using the documentation for version 2.11.7. Go here for the latest version or check here for your available upgrades to ExpressionEngine 3.

Template Language Overview

This page is a quick overview of the syntax and terminology used throughout the user guide when talking about ExpressionEngine Templates (What are Templates?). For more information on each topic, please refer to the additional pages linked in each section or go to the Templates area of this guide for an exhaustive list of all pages covering the template engine. If you’re new to ExpressionEngine you may want to begin with the News Site Tutorial.

If you are a developer, you may also wish to read the Template Class documentation.

ExpressionEngine Code

The content for your template is controlled by ExpressionEngine code. A lot of the syntax used for ExpressionEngine code is modeled after the HTML you already know, making it quick and easy to pick up. ExpressionEngine code must always begin with a { character and end with a } character.

Template Variables

Variables are the primary way to show content in your template. When you need something output to the page, you will usually use a variable.

Single Variables

Single variables will output a single piece of content:


More Information: Standard Global Variables

Variable Pairs

Variable pairs expose several single variables between them to allow for more granular access to the data than their single variable counterparts:

{news_image} {!-- shows: <img src="image.ext" alt="file_name" /> --}

    File name: {file_name}
    File extension: {extension}
    Url: {url}

More Information: File Field Variable Pair

Template Tags

Template tags are the control structures of your template. They can provide and manipulate variables and template contents, but they typically will not output much data on their own.

Comment Tags

Comments are removed from the template before it is shown:

{!-- This is a comment --}

More Information: Commenting Template Code

Module and Plugin Tags

Modules and Plugins are your main data providers. They can be easily spotted, because they all start with {exp:. They most frequently come in pairs that loop over rows of content. The template chunk between them will be repeated for each row they represent, and the variables between them will be replaced with the values of each row of content:

{!-- show a list of all entry titles and their author --}
  <h1>{title} <span>{author}</h1>


Occasionally these can be used as single tags. In those cases they work like single variables. Refer to the documentation of each add-on to learn about how it is used.

More Information: Channel Module, Add-Ons, Using Plugins


You can show or hide template data based on the current user or based on any other content using conditional tags. Please note that when variables are used inside conditionals they do not need to be surrounded by { or }:

{logged_in_username} {!-- outputs Bob --}
{if logged_in_username == "Bob"}Hi Bob{/if}

More Information: Conditionals, Tags within Conditionals

Embedded Templates

Templates can be embedded in other templates. This way you can create reusable template partials:


More Information: Embeds


You can wrap a template in a layout to reuse wrapping code between several templates:


More Information: Layouts


Many ExpressionEngine tags and variables can accept parameters. Parameters are used to change how the tag or variable behaves. They look just like HTML parameters, with a name and a value:

{!-- show the five latest news entry titles --}
{exp:channel:entries channel="news" limit="5"}

Common Tasks

Formatting Dates

ExpressionEngine stores dates as unix timestamps (seconds since 1970). The format parameter is used to to create flexible date output:

{current_time format="%F %d %Y"} {!-- March 22 2014 --}

More Information: Date Formatting

Accessing the URL

The {segment_#} variables allow you to access the different parts of the current ExpressionEngine URL:

{segment_1} {!-- usually the template group --}
{segment_2} {!-- usually the template name --}

The {current_url} and {current_path} variables give you access to the full url and the path (all segments), respectively:

{current_url} {!-- --}
{current_path} {!-- /something/great --}

More Information: URL Segment Variables

Adding CSS and JavaScript

Your external assets can be linked to as you normally would. They do not themselves need to be templates:

<link rel="stylesheet" href="/styles/main.css" type="text/css" />
<script src="/js/main.js"></script>

If you do want to keep your CSS in a template, you can use the {stylesheet= tag to let ExpressionEngine attempt to optimize how it serves the template:

<link rel="stylesheet" href="{stylesheet='group/template'}" type="text/css" />

More Information: Linking to Stylesheets, ExpressionEngine Code in Stylesheets