templates.rst 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  1. Twig for Template Designers
  2. ===========================
  3. This document describes the syntax and semantics of the template engine and
  4. will be most useful as reference to those creating Twig templates.
  5. Synopsis
  6. --------
  7. A template is simply a text file. It can generate any text-based format (HTML,
  8. XML, CSV, LaTeX, etc.). It doesn't have a specific extension, ``.html`` or
  9. ``.xml`` are just fine.
  10. A template contains **variables** or **expressions**, which get replaced with
  11. values when the template is evaluated, and **tags**, which control the logic
  12. of the template.
  13. Below is a minimal template that illustrates a few basics. We will cover the
  14. details later on:
  15. .. code-block:: html+jinja
  16. <!DOCTYPE html>
  17. <html>
  18. <head>
  19. <title>My Webpage</title>
  20. </head>
  21. <body>
  22. <ul id="navigation">
  23. {% for item in navigation %}
  24. <li><a href="{{ item.href }}">{{ item.caption }}</a></li>
  25. {% endfor %}
  26. </ul>
  27. <h1>My Webpage</h1>
  28. {{ a_variable }}
  29. </body>
  30. </html>
  31. There are two kinds of delimiters: ``{% ... %}`` and ``{{ ... }}``. The first
  32. one is used to execute statements such as for-loops, the latter prints the
  33. result of an expression to the template.
  34. IDEs Integration
  35. ----------------
  36. Many IDEs support syntax highlighting and auto-completion for Twig:
  37. * *Textmate* via the `Twig bundle`_
  38. * *Vim* via the `Jinja syntax plugin`_
  39. * *Netbeans* via the `Twig syntax plugin`_
  40. * *PhpStorm* (native as of 2.1)
  41. * *Eclipse* via the `Twig plugin`_
  42. * *Sublime Text* via the `Twig bundle`_
  43. * *GtkSourceView* via the `Twig language definition`_ (used by gedit and other projects)
  44. * *Coda* and *SubEthaEdit* via the `Twig syntax mode`_
  45. * *Coda 2* via the `other Twig syntax mode`_
  46. * *Komodo* and *Komodo Edit* via the Twig highlight/syntax check mode
  47. * *Notepad++* via the `Notepad++ Twig Highlighter`_
  48. Variables
  49. ---------
  50. The application passes variables to the templates you can mess around in the
  51. template. Variables may have attributes or elements on them you can access
  52. too. How a variable looks like heavily depends on the application providing
  53. those.
  54. You can use a dot (``.``) to access attributes of a variable (methods or
  55. properties of a PHP object, or items of a PHP array), or the so-called
  56. "subscript" syntax (``[]``):
  57. .. code-block:: jinja
  58. {{ foo.bar }}
  59. {{ foo['bar'] }}
  60. When the attribute contains special characters (like ``-`` that would be
  61. interpreted as the minus operator), use the ``attribute`` function instead to
  62. access the variable attribute:
  63. .. code-block:: jinja
  64. {# equivalent to the non-working foo.data-foo #}
  65. {{ attribute(foo, 'data-foo') }}
  66. .. note::
  67. It's important to know that the curly braces are *not* part of the
  68. variable but the print statement. If you access variables inside tags
  69. don't put the braces around.
  70. If a variable or attribute does not exist, you will get back a ``null`` value
  71. when the ``strict_variables`` option is set to ``false``, otherwise Twig will
  72. throw an error (see :ref:`environment options<environment_options>`).
  73. .. sidebar:: Implementation
  74. For convenience sake ``foo.bar`` does the following things on the PHP
  75. layer:
  76. * check if ``foo`` is an array and ``bar`` a valid element;
  77. * if not, and if ``foo`` is an object, check that ``bar`` is a valid property;
  78. * if not, and if ``foo`` is an object, check that ``bar`` is a valid method
  79. (even if ``bar`` is the constructor - use ``__construct()`` instead);
  80. * if not, and if ``foo`` is an object, check that ``getBar`` is a valid method;
  81. * if not, and if ``foo`` is an object, check that ``isBar`` is a valid method;
  82. * if not, return a ``null`` value.
  83. ``foo['bar']`` on the other hand only works with PHP arrays:
  84. * check if ``foo`` is an array and ``bar`` a valid element;
  85. * if not, return a ``null`` value.
  86. .. note::
  87. If you want to get a dynamic attribute on a variable, use the
  88. :doc:`attribute<functions/attribute>` function instead.
  89. Global Variables
  90. ~~~~~~~~~~~~~~~~
  91. The following variables are always available in templates:
  92. * ``_self``: references the current template;
  93. * ``_context``: references the current context;
  94. * ``_charset``: references the current charset.
  95. Setting Variables
  96. ~~~~~~~~~~~~~~~~~
  97. You can assign values to variables inside code blocks. Assignments use the
  98. :doc:`set<tags/set>` tag:
  99. .. code-block:: jinja
  100. {% set foo = 'foo' %}
  101. {% set foo = [1, 2] %}
  102. {% set foo = {'foo': 'bar'} %}
  103. Filters
  104. -------
  105. Variables can be modified by **filters**. Filters are separated from the
  106. variable by a pipe symbol (``|``) and may have optional arguments in
  107. parentheses. Multiple filters can be chained. The output of one filter is
  108. applied to the next.
  109. The following example removes all HTML tags from the ``name`` and title-cases
  110. it:
  111. .. code-block:: jinja
  112. {{ name|striptags|title }}
  113. Filters that accept arguments have parentheses around the arguments. This
  114. example will join a list by commas:
  115. .. code-block:: jinja
  116. {{ list|join(', ') }}
  117. To apply a filter on a section of code, wrap it with the
  118. :doc:`filter<tags/filter>` tag:
  119. .. code-block:: jinja
  120. {% filter upper %}
  121. This text becomes uppercase
  122. {% endfilter %}
  123. Go to the :doc:`filters<filters/index>` page to learn more about the built-in
  124. filters.
  125. Functions
  126. ---------
  127. Functions can be called to generate content. Functions are called by their
  128. name followed by parentheses (``()``) and may have arguments.
  129. For instance, the ``range`` function returns a list containing an arithmetic
  130. progression of integers:
  131. .. code-block:: jinja
  132. {% for i in range(0, 3) %}
  133. {{ i }},
  134. {% endfor %}
  135. Go to the :doc:`functions<functions/index>` page to learn more about the
  136. built-in functions.
  137. Control Structure
  138. -----------------
  139. A control structure refers to all those things that control the flow of a
  140. program - conditionals (i.e. ``if``/``elseif``/``else``), ``for``-loops, as
  141. well as things like blocks. Control structures appear inside ``{% ... %}``
  142. blocks.
  143. For example, to display a list of users provided in a variable called
  144. ``users``, use the :doc:`for<tags/for>` tag:
  145. .. code-block:: jinja
  146. <h1>Members</h1>
  147. <ul>
  148. {% for user in users %}
  149. <li>{{ user.username|e }}</li>
  150. {% endfor %}
  151. </ul>
  152. The :doc:`if<tags/if>` tag can be used to test an expression:
  153. .. code-block:: jinja
  154. {% if users|length > 0 %}
  155. <ul>
  156. {% for user in users %}
  157. <li>{{ user.username|e }}</li>
  158. {% endfor %}
  159. </ul>
  160. {% endif %}
  161. Go to the :doc:`tags<tags/index>` page to learn more about the built-in tags.
  162. Comments
  163. --------
  164. To comment-out part of a line in a template, use the comment syntax ``{# ...
  165. #}``. This is useful for debugging or to add information for other template
  166. designers or yourself:
  167. .. code-block:: jinja
  168. {# note: disabled template because we no longer use this
  169. {% for user in users %}
  170. ...
  171. {% endfor %}
  172. #}
  173. Including other Templates
  174. -------------------------
  175. The :doc:`include<tags/include>` tag is useful to include a template and
  176. return the rendered content of that template into the current one:
  177. .. code-block:: jinja
  178. {% include 'sidebar.html' %}
  179. Per default included templates are passed the current context.
  180. The context that is passed to the included template includes variables defined
  181. in the template:
  182. .. code-block:: jinja
  183. {% for box in boxes %}
  184. {% include "render_box.html" %}
  185. {% endfor %}
  186. The included template ``render_box.html`` is able to access ``box``.
  187. The filename of the template depends on the template loader. For instance, the
  188. ``Twig_Loader_Filesystem`` allows you to access other templates by giving the
  189. filename. You can access templates in subdirectories with a slash:
  190. .. code-block:: jinja
  191. {% include "sections/articles/sidebar.html" %}
  192. This behavior depends on the application embedding Twig.
  193. Template Inheritance
  194. --------------------
  195. The most powerful part of Twig is template inheritance. Template inheritance
  196. allows you to build a base "skeleton" template that contains all the common
  197. elements of your site and defines **blocks** that child templates can
  198. override.
  199. Sounds complicated but is very basic. It's easier to understand it by
  200. starting with an example.
  201. Let's define a base template, ``base.html``, which defines a simple HTML
  202. skeleton document that you might use for a simple two-column page:
  203. .. code-block:: html+jinja
  204. <!DOCTYPE html>
  205. <html>
  206. <head>
  207. {% block head %}
  208. <link rel="stylesheet" href="style.css" />
  209. <title>{% block title %}{% endblock %} - My Webpage</title>
  210. {% endblock %}
  211. </head>
  212. <body>
  213. <div id="content">{% block content %}{% endblock %}</div>
  214. <div id="footer">
  215. {% block footer %}
  216. &copy; Copyright 2011 by <a href="http://domain.invalid/">you</a>.
  217. {% endblock %}
  218. </div>
  219. </body>
  220. </html>
  221. In this example, the :doc:`block<tags/block>` tags define four blocks that
  222. child templates can fill in. All the ``block`` tag does is to tell the
  223. template engine that a child template may override those portions of the
  224. template.
  225. A child template might look like this:
  226. .. code-block:: jinja
  227. {% extends "base.html" %}
  228. {% block title %}Index{% endblock %}
  229. {% block head %}
  230. {{ parent() }}
  231. <style type="text/css">
  232. .important { color: #336699; }
  233. </style>
  234. {% endblock %}
  235. {% block content %}
  236. <h1>Index</h1>
  237. <p class="important">
  238. Welcome to my awesome homepage.
  239. </p>
  240. {% endblock %}
  241. The :doc:`extends<tags/extends>` tag is the key here. It tells the template
  242. engine that this template "extends" another template. When the template system
  243. evaluates this template, first it locates the parent. The extends tag should
  244. be the first tag in the template.
  245. Note that since the child template doesn't define the ``footer`` block, the
  246. value from the parent template is used instead.
  247. It's possible to render the contents of the parent block by using the
  248. :doc:`parent<functions/parent>` function. This gives back the results of the
  249. parent block:
  250. .. code-block:: jinja
  251. {% block sidebar %}
  252. <h3>Table Of Contents</h3>
  253. ...
  254. {{ parent() }}
  255. {% endblock %}
  256. .. tip::
  257. The documentation page for the :doc:`extends<tags/extends>` tag describes
  258. more advanced features like block nesting, scope, dynamic inheritance, and
  259. conditional inheritance.
  260. .. note::
  261. Twig also supports multiple inheritance with the so called horizontal reuse
  262. with the help of the :doc:`use<tags/use>` tag. This is an advanced feature
  263. hardly ever needed in regular templates.
  264. HTML Escaping
  265. -------------
  266. When generating HTML from templates, there's always a risk that a variable
  267. will include characters that affect the resulting HTML. There are two
  268. approaches: manually escaping each variable or automatically escaping
  269. everything by default.
  270. Twig supports both, automatic escaping is enabled by default.
  271. .. note::
  272. Automatic escaping is only supported if the *escaper* extension has been
  273. enabled (which is the default).
  274. Working with Manual Escaping
  275. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  276. If manual escaping is enabled, it is **your** responsibility to escape
  277. variables if needed. What to escape? Any variable you don't trust.
  278. Escaping works by piping the variable through the
  279. :doc:`escape<filters/escape>` or ``e`` filter:
  280. .. code-block:: jinja
  281. {{ user.username|e }}
  282. By default, the ``escape`` filter uses the ``html`` strategy, but depending on
  283. the escaping context, you might want to explicitly use any other available
  284. strategies:
  285. {{ user.username|e('js') }}
  286. {{ user.username|e('css') }}
  287. {{ user.username|e('url') }}
  288. {{ user.username|e('html_attr') }}
  289. Working with Automatic Escaping
  290. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  291. Whether automatic escaping is enabled or not, you can mark a section of a
  292. template to be escaped or not by using the :doc:`autoescape<tags/autoescape>`
  293. tag:
  294. .. code-block:: jinja
  295. {% autoescape %}
  296. Everything will be automatically escaped in this block (using the HTML strategy)
  297. {% endautoescape %}
  298. By default, auto-escaping uses the ``html`` escaping strategy. If you output
  299. variables in other contexts, you need to explicitly escape them with the
  300. appropriate escaping strategy:
  301. .. code-block:: jinja
  302. {% autoescape 'js' %}
  303. Everything will be automatically escaped in this block (using the JS strategy)
  304. {% endautoescape %}
  305. Escaping
  306. --------
  307. It is sometimes desirable or even necessary to have Twig ignore parts it would
  308. otherwise handle as variables or blocks. For example if the default syntax is
  309. used and you want to use ``{{`` as raw string in the template and not start a
  310. variable you have to use a trick.
  311. The easiest way is to output the variable delimiter (``{{``) by using a variable
  312. expression:
  313. .. code-block:: jinja
  314. {{ '{{' }}
  315. For bigger sections it makes sense to mark a block :doc:`raw<tags/raw>`.
  316. Macros
  317. ------
  318. Macros are comparable with functions in regular programming languages. They
  319. are useful to reuse often used HTML fragments to not repeat yourself.
  320. A macro is defined via the :doc:`macro<tags/macro>` tag. Here is a small example
  321. (subsequently called ``forms.html``) of a macro that renders a form element:
  322. .. code-block:: jinja
  323. {% macro input(name, value, type, size) %}
  324. <input type="{{ type|default('text') }}" name="{{ name }}" value="{{ value|e }}" size="{{ size|default(20) }}" />
  325. {% endmacro %}
  326. Macros can be defined in any template, and need to be "imported" via the
  327. :doc:`import<tags/import>` tag before being used:
  328. .. code-block:: jinja
  329. {% import "forms.html" as forms %}
  330. <p>{{ forms.input('username') }}</p>
  331. Alternatively, you can import individual macro names from a template into the
  332. current namespace via the :doc:`from<tags/from>` tag and optionally alias them:
  333. .. code-block:: jinja
  334. {% from 'forms.html' import input as input_field %}
  335. <dl>
  336. <dt>Username</dt>
  337. <dd>{{ input_field('username') }}</dd>
  338. <dt>Password</dt>
  339. <dd>{{ input_field('password', '', 'password') }}</dd>
  340. </dl>
  341. Expressions
  342. -----------
  343. Twig allows expressions everywhere. These work very similar to regular PHP and
  344. even if you're not working with PHP you should feel comfortable with it.
  345. .. note::
  346. The operator precedence is as follows, with the lowest-precedence
  347. operators listed first: ``b-and``, ``b-xor``, ``b-or``, ``or``, ``and``,
  348. ``==``, ``!=``, ``<``, ``>``, ``>=``, ``<=``, ``in``, ``..``, ``+``,
  349. ``-``, ``~``, ``*``, ``/``, ``//``, ``%``, ``is``, and ``**``.
  350. Literals
  351. ~~~~~~~~
  352. .. versionadded:: 1.5
  353. Support for hash keys as names and expressions was added in Twig 1.5.
  354. The simplest form of expressions are literals. Literals are representations
  355. for PHP types such as strings, numbers, and arrays. The following literals
  356. exist:
  357. * ``"Hello World"``: Everything between two double or single quotes is a
  358. string. They are useful whenever you need a string in the template (for
  359. example as arguments to function calls, filters or just to extend or
  360. include a template).
  361. * ``42`` / ``42.23``: Integers and floating point numbers are created by just
  362. writing the number down. If a dot is present the number is a float,
  363. otherwise an integer.
  364. * ``["foo", "bar"]``: Arrays are defined by a sequence of expressions
  365. separated by a comma (``,``) and wrapped with squared brackets (``[]``).
  366. * ``{"foo": "bar"}``: Hashes are defined by a list of keys and values
  367. separated by a comma (``,``) and wrapped with curly braces (``{}``):
  368. .. code-block:: jinja
  369. {# keys as string #}
  370. { 'foo': 'foo', 'bar': 'bar' }
  371. {# keys as names (equivalent to the previous hash) -- as of Twig 1.5 #}
  372. { foo: 'foo', bar: 'bar' }
  373. {# keys as integer #}
  374. { 2: 'foo', 4: 'bar' }
  375. {# keys as expressions (the expression must be enclosed into parentheses) -- as of Twig 1.5 #}
  376. { (1 + 1): 'foo', (a ~ 'b'): 'bar' }
  377. * ``true`` / ``false``: ``true`` represents the true value, ``false``
  378. represents the false value.
  379. * ``null``: ``null`` represents no specific value. This is the value returned
  380. when a variable does not exist. ``none`` is an alias for ``null``.
  381. Arrays and hashes can be nested:
  382. .. code-block:: jinja
  383. {% set foo = [1, {"foo": "bar"}] %}
  384. Math
  385. ~~~~
  386. Twig allows you to calculate with values. This is rarely useful in templates
  387. but exists for completeness' sake. The following operators are supported:
  388. * ``+``: Adds two objects together (the operands are casted to numbers). ``{{
  389. 1 + 1 }}`` is ``2``.
  390. * ``-``: Substracts the second number from the first one. ``{{ 3 - 2 }}`` is
  391. ``1``.
  392. * ``/``: Divides two numbers. The returned value will be a floating point
  393. number. ``{{ 1 / 2 }}`` is ``{{ 0.5 }}``.
  394. * ``%``: Calculates the remainder of an integer division. ``{{ 11 % 7 }}`` is
  395. ``4``.
  396. * ``//``: Divides two numbers and returns the truncated integer result. ``{{
  397. 20 // 7 }}`` is ``2``.
  398. * ``*``: Multiplies the left operand with the right one. ``{{ 2 * 2 }}`` would
  399. return ``4``.
  400. * ``**``: Raises the left operand to the power of the right operand. ``{{ 2 **
  401. 3 }}`` would return ``8``.
  402. Logic
  403. ~~~~~
  404. You can combine multiple expressions with the following operators:
  405. * ``and``: Returns true if the left and the right operands are both true.
  406. * ``or``: Returns true if the left or the right operand is true.
  407. * ``not``: Negates a statement.
  408. * ``(expr)``: Groups an expression.
  409. .. note::
  410. Twig also support bitwise operators (``b-and``, ``b-xor``, and ``b-or``).
  411. Comparisons
  412. ~~~~~~~~~~~
  413. The following comparison operators are supported in any expression: ``==``,
  414. ``!=``, ``<``, ``>``, ``>=``, and ``<=``.
  415. Containment Operator
  416. ~~~~~~~~~~~~~~~~~~~~
  417. The ``in`` operator performs containment test.
  418. It returns ``true`` if the left operand is contained in the right:
  419. .. code-block:: jinja
  420. {# returns true #}
  421. {{ 1 in [1, 2, 3] }}
  422. {{ 'cd' in 'abcde' }}
  423. .. tip::
  424. You can use this filter to perform a containment test on strings, arrays,
  425. or objects implementing the ``Traversable`` interface.
  426. To perform a negative test, use the ``not in`` operator:
  427. .. code-block:: jinja
  428. {% if 1 not in [1, 2, 3] %}
  429. {# is equivalent to #}
  430. {% if not (1 in [1, 2, 3]) %}
  431. Test Operator
  432. ~~~~~~~~~~~~~
  433. The ``is`` operator performs tests. Tests can be used to test a variable against
  434. a common expression. The right operand is name of the test:
  435. .. code-block:: jinja
  436. {# find out if a variable is odd #}
  437. {{ name is odd }}
  438. Tests can accept arguments too:
  439. .. code-block:: jinja
  440. {% if loop.index is divisibleby(3) %}
  441. Tests can be negated by using the ``is not`` operator:
  442. .. code-block:: jinja
  443. {% if loop.index is not divisibleby(3) %}
  444. {# is equivalent to #}
  445. {% if not (loop.index is divisibleby(3)) %}
  446. Go to the :doc:`tests<tests/index>` page to learn more about the built-in
  447. tests.
  448. Other Operators
  449. ~~~~~~~~~~~~~~~
  450. The following operators are very useful but don't fit into any of the other
  451. categories:
  452. * ``..``: Creates a sequence based on the operand before and after the
  453. operator (this is just syntactic sugar for the :doc:`range<functions/range>`
  454. function).
  455. * ``|``: Applies a filter.
  456. * ``~``: Converts all operands into strings and concatenates them. ``{{ "Hello
  457. " ~ name ~ "!" }}`` would return (assuming ``name`` is ``'John'``) ``Hello
  458. John!``.
  459. * ``.``, ``[]``: Gets an attribute of an object.
  460. * ``?:``: The PHP ternary operator: ``{{ foo ? 'yes' : 'no' }}``
  461. String Interpolation
  462. ~~~~~~~~~~~~~~~~~~~~
  463. .. versionadded:: 1.5
  464. String interpolation was added in Twig 1.5.
  465. String interpolation (`#{expression}`) allows any valid expression to appear
  466. within a string. The result of evaluating that expression is inserted into the
  467. string:
  468. .. code-block:: jinja
  469. {{ "foo #{bar} baz" }}
  470. {{ "foo #{1 + 2} baz" }}
  471. Whitespace Control
  472. ------------------
  473. .. versionadded:: 1.1
  474. Tag level whitespace control was added in Twig 1.1.
  475. The first newline after a template tag is removed automatically (like in PHP.)
  476. Whitespace is not further modified by the template engine, so each whitespace
  477. (spaces, tabs, newlines etc.) is returned unchanged.
  478. Use the ``spaceless`` tag to remove whitespace *between HTML tags*:
  479. .. code-block:: jinja
  480. {% spaceless %}
  481. <div>
  482. <strong>foo</strong>
  483. </div>
  484. {% endspaceless %}
  485. {# output will be <div><strong>foo</strong></div> #}
  486. In addition to the spaceless tag you can also control whitespace on a per tag
  487. level. By using the whitespace control modifier on your tags, you can trim
  488. leading and or trailing whitespace:
  489. .. code-block:: jinja
  490. {% set value = 'no spaces' %}
  491. {#- No leading/trailing whitespace -#}
  492. {%- if true -%}
  493. {{- value -}}
  494. {%- endif -%}
  495. {# output 'no spaces' #}
  496. The above sample shows the default whitespace control modifier, and how you can
  497. use it to remove whitespace around tags. Trimming space will consume all whitespace
  498. for that side of the tag. It is possible to use whitespace trimming on one side
  499. of a tag:
  500. .. code-block:: jinja
  501. {% set value = 'no spaces' %}
  502. <li> {{- value }} </li>
  503. {# outputs '<li>no spaces </li>' #}
  504. Extensions
  505. ----------
  506. Twig can be easily extended.
  507. If you are looking for new tags, filters, or functions, have a look at the Twig official
  508. `extension repository`_.
  509. If you want to create your own, read the :ref:`Creating an
  510. Extension<creating_extensions>` chapter.
  511. .. _`Twig bundle`: https://github.com/Anomareh/PHP-Twig.tmbundle
  512. .. _`Jinja syntax plugin`: http://jinja.pocoo.org/2/documentation/integration
  513. .. _`Twig syntax plugin`: http://plugins.netbeans.org/plugin/37069/php-twig
  514. .. _`Twig plugin`: https://github.com/pulse00/Twig-Eclipse-Plugin
  515. .. _`Twig language definition`: https://github.com/gabrielcorpse/gedit-twig-template-language
  516. .. _`extension repository`: http://github.com/fabpot/Twig-extensions
  517. .. _`Twig syntax mode`: https://github.com/bobthecow/Twig-HTML.mode
  518. .. _`other Twig syntax mode`: https://github.com/muxx/Twig-HTML.mode
  519. .. _`Notepad++ Twig Highlighter`: https://github.com/Banane9/notepadplusplus-twig