TWIG tests learning

Source: Internet
Author: User
Make logical judgments. Currently, token checking is supported to check whether {% ifloop. indexisdivisibleby (3) %}... {% endif %} {% ifloop. indexi...

Make logical judgments. Currently

Divisibleby null even odd sameas constant defined empty

 

 

Divisibleby
Check whether it can be divisible

{% If loop. index is divisibleby (3) %}
...
{% Endif %}
{% If loop. index is divisibleby (3) %}
...
{% Endif %}

 

Null
{Var is null }}
{Var is null }}

 

Even
Whether the variable is an even number {var is even }}
{Var is even }}


Odd
Whether the variable is an odd number

{Var is odd }}
{Var is odd }}

 

 

Sameas
Check whether the address of the variable is the same

{% If foo. attribute is sameas (false) %}
The foo attribute really is the ''false'' PHP value
{% Endif %}
{% If foo. attribute is sameas (false) %}
The foo attribute really is the ''false'' PHP value
{% Endif %}

 

Constant
Check whether the value of the variable is the same

{% If post. status is constant ('post: hhed ') %}
The status attribute is exactly the same as Post: PUBLISHED
{% Endif %}
{% If post. status is constant ('post: hhed ') %}
The status attribute is exactly the same as Post: PUBLISHED
{% Endif %}

 

Defined
Test whether the variable is defined

{# Defined works with variable names #}
{% If foo is defined %}
...
{% Endif %}
 
{# And attributes on variables names #}
{% If foo. bar is defined %}
...
{% Endif %}
 
{% If foo ['bar'] is defined %}
...
{% Endif %}
{# Defined works with variable names #}
{% If foo is defined %}
...
{% Endif %}

{# And attributes on variables names #}
{% If foo. bar is defined %}
...
{% Endif %}

{% If foo ['bar'] is defined %}
...
{% Endif %}

 

Empty
Test whether the variable is null. empty indicates that the variable has been defined, but its value is null false or an empty string.
{# Evaluates to true if the foo variable is null, false, or the empty string #}
{% If foo is empty %}
...
{% Endif %}

From the column jiaochangyun

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.