JoonWeb template documentation
JW Template supports basic operators that could be used in conditions and tags to ensure a enchanic ability for designers to do dynamic things with their templates by using operators such as:
Operator Function
Operator | Defination |
---|---|
== | equals |
!= | does not equal |
> | greater than |
< | less than |
>= | greater than or equal to |
<= | less than or equal to |
or | or Condition A or Condition B |
and | and Condition A and Condition |
{% if blog.items %}
<ul class="articles">
{% for post in blog.items %}
<li>
<a href="{{post.url}}"><div class="list-head">{{post.title}}</div></a>
</li>
{% endfor %}
</ul>
{% endif %}
The above code iterates over each item in a sequence and displays it in a list format.
{% for i in 0..10 %}
* {{ i }}
{% endfor %}
The above code will print all numbers from 0 to 10. The `..` operator can also be used with letters:
{% for letter in 'a'..'z' %}
* {{ letter }}
{% endfor %}
The above code will print all numbers from 0 to 10. The `..` operator can also be used with letters:
If a step different from 1 is needed, the range function can be used instead.
The loop variable provides information about the current iteration of the loop. It includes the following variables:
{% for user in users %}
{{ loop.index }} - {{ user.name }}
{% endfor %}
<ul>
{% for user in users if user.active %}
<li>{{ user.name }}</li>
{% endfor %}
</ul>
If no iteration takes place because the sequence is empty, the `else` clause can be used to display a replacement block example:
<ul>
{% for user in users %}
<li>{{ user.username }}</li>
{% else %}
<li><em>no user found</em></li>
{% endfor %}
</ul>
<h1>Products</h1>
<ul>
{% for key in products|keys %}
<li>{{ key }}</li>
{% endfor %}
</ul>
To access both keys and values, the following code can be:
<h1>Products</h1>
<ul>
{% for key, product in products %}
<li>{{ key }}: {{ product.title }}</li>
{% endfor %}
</ul>
<h1>Top 5 Products</h1>
<ul>
{% for product in products|slice(0, 5) %}
<li>{{ product.title }}</li>
{% endfor %}
</ul>
In this example, the `slice` filter is used to get the first 5 items from the products array sequence and iterate over them.Filter | Details |
---|---|
date | Help in modify the given date format like {{ "now"| date("m/d/Y") }} {{ post.created | date("d-m-y") }} |
date_modify | Usage: {{ post.created | date_modify("+1 day")| date("m/d/Y") }} |
escape | for escaping input, {{ user.name | escape }} |
format_currency | for adding currency in price |
join | joining array |
keys | helpful during loops |
length | For get length of Array/Object {{ items | length }} |
lower | For making lower character {{ "Hello World" | lower }} |
number_format | formating integers in number format |
striptags | removing extra html from input |
trim | trimming spaces |
url_encode | Encoding of url |