How to obtain global variables using the twig template

Source: Internet
Author: User
: 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.

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.