Currently twig built-in functions include
attribute, block, constant, cycle, dump, parent, random, range.
In fact, part of the function, in the study of tags have already seen.
attribute function
1.2 version added
He's the equivalent of a. Operator.
{{Attribute (object, method)}}
{{Attribute (object, method, arguments)}}
{{attribute (array, item)}}
{{Attribute (object, method)}}
{{Attribute (object, method, arguments)}}
{{attribute (array, item)}}
Block function
Outputs the contents of the block block.
{% block title%} {% Endblock%}
{{block (' title ')}}
{% block body%} {% Endblock%}
<title>{% block title%} {% Endblock%}</title>
{{block (' title ')}}
{% block body%} {% Endblock%}
Constant function
Read constant {{Some_date|date (constant (' date_w3c ')}}}
{{constant (' Namespace\\classname::constant_name ')}}
{{Some_date|date (' constant (' date_w3c ')}}}
{{constant (' Namespace\\classname::constant_name ')}}
Cycle function
The contents of the loop output array,
{% Set fruits = [' apple ', ' orange ', ' citrus ']%}
{% for I in 0..10%}
{{cycle (fruits, I)}}
{% ENDFOR%}
{% Set fruits = [' apple ', ' orange ', ' citrus ']%}
{% for I in 0..10%}
{{cycle (fruits, I)}}
{% ENDFOR%}
Dump function
1.5 version added
Print variables, which is the PHP var_dump function,
In addition twig default is not open debug mode, you need to first open his
$twig = new Twig_environment ($loader, $config);
$twig->addextension (New Twig_extension_debug ());
$twig = new Twig_environment ($loader, $config);
$twig->addextension (New Twig_extension_debug ());
You can pass one or more variables, and if you don't pass the variable, he'll print all the variables
{{Dump (user, categories)}}
{{dump ()}}
{{Dump (user, categories)}}
{{dump ()}}
Parent function
Getting the contents of a parent block is especially useful when you're ready to add rather than overwrite
{% extends "base.html"%}
{% block sidebar%}
Table of Contents
...
{{parent ()}}
{% Endblock%}
{% extends "base.html"%}
{% block sidebar%}
Table of Contents
...
{{parent ()}}
{% Endblock%}
Random function
Version 1.5 was added, and a random return from an array
{{[' Apple ', ' orange ', ' Citrus ']}}
{{[' Apple ', ' orange ', ' Citrus ']}}
Range function
Returns an array of numbers, starting with the first argument, ending with the second argument (containing the second one), and the third argument being the step (which can be omitted). and 0.. 101 Samples
{% for I in range (0, 3)%}
{{i}},
{% ENDFOR%}
{# returns 0, 1, 2, 3 #}
{% for I in range (0, 3)%}
{{i}},
{% ENDFOR%}
{# returns 0, 1, 2, 3 #}
and learned a lot. Continue to applause applause. Towards the new page ...
Excerpt from Jiaochangyun's column
http://www.bkjia.com/PHPjc/478457.html www.bkjia.com true http://www.bkjia.com/PHPjc/478457.html techarticle currently twig built-in functions include attribute, block, constant, cycle, dump, parent, random, range. In fact, part of the function, in the study of tags have already seen. Attribute function 1.2 Version new ...