Loading..

Tags 0 0

Last updated on Mar 31, 2019 15:23 in cho Người bán » Thiết lập
Posted BySupport Admin

TagsTrendzy Storefront themes sử dụng ngôn ngữ template dựa trên framework mã nguồn mở, Django. Bạn có thể sử dụng tags, filters và variables để tạo nội dung động trên Storefront.

Tags

Tags let you define a logic and instruct templates. Tags are wrapped in {% %}.

if/elif/else

You can decide which block of templates should be displayed or executed based on conditions:

{% if settings.show_price %}<span>USD ${{thing.sale.price}}</span>{% endif %}

{% if viewer.username == 'jack' %}
Hello, Jack!
{% elif viewer.username == 'joe' %}
Hi, Joe!
{% else %}
Welcome!
{% endif %}

You can also combine filters within your condition:

{% if thing.sale.images|length > 5 %}So many images!{% endif %}

for

You can repeat a block of code with each element in a list:

{% for option in thing.sale.options %}
<option value="{{option.id}}" {%if option.soldout %}disabled{% endif%}>
{{option.title}}
</option>
{% endfor %}

Within a for block, you can use the forloop object to access the current status.

  • forloop.counter contains the current iteration of the loop, starting with 1.
  • forloop.first contains True if this is the first time through the loop.
  • forloop.last contains True if this is the last time through the loop.
  • forloop.parentloop points to the parent forloop object for nested loops.
  • assign

    Creates and assigns new variables.

    {% assign featured=sale_item_dict|get_dict:settings.featured_item_id foo="bar" %}
    Featured Item: {{featured.name}} - {{foo}}

    with

    Assigns variables to use inside a block.

    {% with thing=sale_item_dict|get_dict:settings.featured_item_id %}
    Featured Item: {{thing.name}} - ${{thing.sale.price}}
    {% endwith %}

    ** The time is base on America/New_York timezone