: This article describes how to obtain global variables using the twig template. For more information about PHP tutorials, see. This document describes how to obtain global variables using the twig template. We will share this with you for your reference. The details are as follows:
In brief, twig is a template engine, which can simplify the php compilation process and improve efficiency.
The Symfony template comes with the twig template engine.
Twig syntax is more than three, which is easier.
1. {...} indicates the output variable in twig. for example:
{{ id }}
2. {%... %}. In twig, this indicates making a judgment. for example, it is taken from the official twig document ):
Determine whether the value is true:
{% if online == false %} Our website is in maintenance mode. Please, come back later.
{%endif%}
Whether the value is null:
{% if users %}
{% for user in users %}
- {{ user.username|e }}
{% endfor %}
{% endif %}
Determine whether this value can be found:
{% if users is defined %} {{ user.username|e }}{% endif %}
3 ,{#... #}, Meaning of the comment
The general syntax is introduced, and then how to use twig to output global variables.
I did not find it for half a day, and finally I found it through the wall. the code below
{{ app.session.get('varname') }}
The varname above is the name of the value corresponding to the session array to be output.
We are still learning about the twig template engine. Please confirm and add.
Permanent Address: http://blog.it985.com/6823.html
This article is from the IT985 blog. please indicate the source and relevant links when reprinting.