a Sensio Labs Product

The flexible, fast, and secure
template engine for PHP

Tags » set

Questions & Feedback

License

Creative Commons License Twig documentation is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.

setΒΆ

Inside code blocks you can also assign values to variables. Assignments use the set tag and can have multiple targets:

{% set foo = 'foo' %}

{% set foo = [1, 2] %}

{% set foo = {'foo': 'bar'} %}

{% set foo = 'foo' ~ 'bar' %}

{% set foo, bar = 'foo', 'bar' %}

The set tag can also be used to 'capture' chunks of text:

{% set foo %}
  <div id="pagination">
    ...
  </div>
{% endset %}

Caution

If you enable automatic output escaping, Twig will only consider the content to be safe when capturing chunks of text.

This website is powered by PHP and Twig. The Twig logo is © 2010-2012 Sensio Labs