顯示具有 Jinja 標籤的文章。 顯示所有文章
顯示具有 Jinja 標籤的文章。 顯示所有文章

2014年7月14日 星期一

Convert integer to string in Jinja

{{ 12345678|string }}
{{ 1111|int }}
  
{% if 1111 == '1111' %}
    1111
{% else %}
    2222
{% endif %}




References :
python - Convert integer to string Jinja - Stack Overflow

2014年3月28日 星期五

Execute Python code in Jinja Template

controller.py 
def clever_function():
    return u'HELLO'

app.jinja_env.globals.update(clever_function=clever_function)


view.py 
{{ clever_function() }}
 
 
 
 
References :
Call a python function from jinja2 - Stack Overflow

2014年3月12日 星期三

Jinja Template include file

Include Files

Hello World

{% include "parts/introtext" %}



Requiring Files
{% require %} works like {% include %} but doesn't return the output.
{% require "myblocks" %}
{% require "parts/introtext" as introtext %}

Hello World

{% call "divbox", "intro", introtext %}




References :
Reuse Parts | Jinja Documentation