Latte syntax wasn't invented by engineers but came up from web designer's practical requests. We were looking for the friendliest syntax with which you can write even the most problematic constructions comfortably enough. You will be surprised how much help Latte can be.

You can find tags for advanced layout managing, for template inheritance, nested blocks and so on. Syntax comes from PHP itself so you don't have to learn anything new and you can leverage your know-how.


You can find detailed description of all the built-in tags. Furthermore, you can make your own tags.

Each pair tag, such as {if} … {/if}, operating upon single HTML element can be written in n:attribute notation. So, it is possible to write the {foreach} tag in the same manner:

<ul n:if="$items">
	<li n:foreach="$items as $item">{$item|capitalize}</li>

With n:attributes you can do much more interesting tricks as you will see in a moment.

{$item|capitalize} tag which prints the $item variable contains so called filter, in this case the capitalize filter which makes the first letter of each word uppercase.

A very important feature of Latte is that it escapes variables by default. Escaping is needed when printing a variable because we have to convert all the characters which have a special meaning in HTML to other sequences. In case we forget it can lead to a serious security hole called Cross-Site Scripting (XSS).

Because of different escaping functions that are needed in different documents and different parts of a page, Latte features a unique technology of security which recognizes the context in which the tag is placed and chooses the right escaping mode. You don't have to worry that your coder forgets about it causing you goosebumps because of a security hole. Which is great!

If the $item variable stores an HTML code and you want to print it without any alteration you just add the modifier noescape: {$item|noescape}. Forgetting the modifier mark won't cause any security holes in the spirit of „less code, more security“ principle.

You can still use PHP inside the tags normally, including comments as well. But Latte also extends the PHP syntax with three pleasant features:

  1. we can omit quotes around the strings consisting of letters, numbers, and dashes
  2. short condition notation $a ? 'b' which is the same as $a ? 'b' : null in PHP
  3. you can use optional chaining like $var?->call()?->elem[1]?->item

For example:

{$cond ? hello}  // prints 'hello' if $cond equals true

{$order->item?->name} // means isset($order->item) ? $order->item->name : null

Latte also has a {* comment tag *} which doesn't get printed to the output.


We showed that n:attributes are supposed to be written directly into HTML tags as their special attributes. We also said that every pair tag (e.g. {if} … {/if}) can be written in n:attribute notation. The functionality then corresponds to the HTML element in which it is written:

{var $items = ['I', '♥', 'Nette Framework']}

<p n:foreach="$items as $item">{$item}</p>


<p>Nette Framework</p>

By using inner- prefix we can alter the behavior so that the functionality applies only to the body of the element:

<div n:inner-foreach="$items as $item">


	<p>Nette Framework</p>

Or by using tag- prefix the functionality is applied on the HTML tags only:

<p><a href="{$url}" n:tag-if="$url">Title</a></p>

Depending on the value of $url variable this will print:

// when $url is empty

// when $url equals ''
<p><a href="">Title</a></p>

However, n:attributes are not only a shortcut for pair tags, there are some pure n:attributes as well, for example the coder's best friend n:class.


See the summary of standard filters.

Latte allows calling filters by using the pipe sign notation called modifier (preceding space is allowed):


Filters can be chained, in that case they apply in order from left to right:


Parameters are put after the filter name separated by colon or comma:


Filters can be applied on expression:

{var $name = ($title|upper) . ($subtitle|lower)}</h1>
Improve this page