目前twig内建的函数包括
attribute, block, constant, cycle, dump, parent, random, range.
其实部分函数,在tags的学习里已经见过了。
{{ attribute(object, method) }} {{ attribute(object, method, arguments) }} {{ attribute(array, item) }}
<title>{% block title %}{% endblock %}</title> <h1>{{ block('title') }}</h1> {% block body %}{% endblock %}
{{ some_date|date(constant('DATE_W3C')) }} {{ constant('Namespace\\Classname::CONSTANT_NAME') }}
{% set fruits = ['apple', 'orange', 'citrus'] %} {% for i in 0..10 %} {{ cycle(fruits, i) }} {% endfor %}
$twig = new Twig_Environment($loader, $config); $twig->addExtension(new Twig_Extension_Debug());
{{ dump(user, categories) }} {{ dump() }}
{% extends "base.html" %} {% block sidebar %} <h3>Table Of Contents</h3> ... {{ parent() }} {% endblock %}
{{ random(['apple', 'orange', 'citrus']) }}
{% for i in range(0, 3) %} {{ i }}, {% endfor %} {# returns 0, 1, 2, 3 #}