Surge. js updated version 0.2.3 Alpha, added support for the with tag, and removed context references from the template.

Source: Internet
Author: User

 

Surge. js updated version 0.2.3 Alpha, added support for the with Tag, removed context reference from the template, and fixed the bug of the if tag.

Remove context

Surge. js compiles the Template into a js function, which receives a context parameter. Therefore, the variables in the template must be attributes in the context, as shown in the following code:

{% for item in context.products %}

The new version does not need to directly reference context in the template, but must be written as follows:

{% for item in products %}
Add with Tag

The with Mark is added in the new version. Unlike the with statement in js, The with Mark in surge. js is similar to returning a name to the variable, for example:

{% with total = products.length %}{{ total }}{% endwith %}

The code is consistent with the following code:

{{ products.length }}

The with Tag supports defining multiple variables, which are separated by spaces or commas (,), as follows:

{% with total = products.length ps = products %}{% endwith %}

Or

{% with total = products.length, ps = products %}{% endwith %}
If tag

The if tag supports multiple forms, such:

The following statement indicates whether products is null, for example, null, [], false.

{% if products %}{% endif %}

The following code is similar to the js judgment statement, with the same effect as above:

{% if products.length > 0 %}{% endif %}

The following statement will convert to js Code:

{% if 0 < product.length < 10 %}{% endif %}{% if 0 < product.length and products.length > 0 %}{% endif %}

Convert to js Code as follows:

if(0 < products.length < 10){}if(0 < products.length && products.length > 0){}

The more complex if tag can contain filter, as shown below:

{% if products.length > 0 and products|somefilter:argument > 0 %}{% endif %}

Convert to js Code:

if(products.length > 0 && somefilter(products, argument) > 0){}

Related Article

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.