Twig template Get global variable method, twig template global variable _php tutorial

Source: Internet
Author: User
Tags php template smarty template

Twig template Get global variable method, twig template global variable


The example in this article describes how the twig template obtains global variables. Share to everyone for your reference, as follows:

In brief, Twig is a template engine that simplifies the process of writing PHP and improves efficiency.

In the Symfony template, it comes with the Twig template engine.

Twig grammar with a lot of, also three kinds, is also relatively easy

1, {{.}}, this is the meaning of the output variable in twig , for instance:

{{id}}

2. {%...%}, which is represented in twig, for example (taken from an example of an official twig document):

Determine if the value is true:

{% if online = = False%}  

Our website are in maintenance mode. Please, come back later.

{%endif%}

Determine if the value is empty:

{% If users%}  
 
  
  
    {% for user in users%}
  • {{User.username|e}}
  • {% endfor%}
{% ENDIF%}

Determine if this value can be found:

{% If users is defined%}  
  • {{User.username|e}}
  • {% ENDIF%}

    3, {#...#}, the meaning of the note

    The approximate syntax is finished, and then this is how to use twig to output global variables.
    Searched for a long while did not find, finally turned over the wall found, the following code

    {{App.session.get (' varname ')}}

    The above varname is the name of the corresponding value in the session array that needs to be output.

    We are still continuing to learn twig this template engine. Welcome to correct, Add.

    Permanent address of this article: http://blog.it985.com/6823.html
    This article is from IT985 blog, please indicate the source and corresponding link when reproduced.

    More about PHP template related content readers can view the site topics: "PHP Template Technology Summary", "Smarty Template Primer Basic Tutorial", "CodeIgniter Introductory Tutorial" and "thinkphp Introductory tutorial"

    I hope this article is helpful to you in PHP programming.

    Articles you may be interested in:

      • The method of using JS variable in twig
      • Twig Template Common Statement instance summary
      • Twig template engine usage Getting Started tutorial
      • Examples of using the PHP template engine twig in the YII framework

    http://www.bkjia.com/PHPjc/1099082.html www.bkjia.com true http://www.bkjia.com/PHPjc/1099082.html techarticle twig Template Get global variable method, twig template global variable This article describes the method by which the Twig template obtains global variables. Share to everyone for your reference, as follows: Simple medium ...

  • 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.