{% extends "base.tmpl" %} {% block main %} include test ============ {% include "header.tmpl" %} binop ====== 1+1 = {{ 1 + 1 }} 1-1 = {{ 1 - 1 }} 2*4 = {{ 2 * 4 }} 4/2 = {{ 4 / 2 }} 8^3 = {{ 8 ** 3 }} 8%3 = {{ 8 % 3 }} not true = {{ !true }} not true(2) = {{ not true }} single quote string test ========================= {% set single_quoted = 'hoge' %} single_quoted = {{single_quoted}} expand test =========== {% set danger = "" %} expand with escape = {{ danger }} expand with safe = {{ danger|safe }} set test ========= set hoge = "ok" {% set hoge = "ok" %} now hoge = {{ hoge }} if test ======= {% if hoge == "ok" %} value of hoge == "ok" {% else %} value of hoge != "ok" {% endif %} for test ======== {% for item in [1,2,3,4,5] %} {% set tmp = "hoge" %}

{{item}}

{{loop.cycle(1,2,3)}}

tmp = {{item}}

{% endfor %} {% for href, title in [ ("http://yahoo.co.jp", "yahoo japan") ] %} {{title}} {% endfor %} {% for href, title in [("http://yahoo.co.jp", "yahoo japan"), ("http://google.co.jp", "google japan")] %} {{title}} {% endfor %} {% for href, title in [("http://yahoo.co.jp", "yahoo japan"), ("http://google.co.jp", "google japan")] %} {{title}} {% endfor %} obj test ========= {% set obj = { age:10, name: 'aa' } %} name = {{obj.name}} age = {{obj.age}} obj["name"] = {{ obj["name"] }} obj["age"] = {{ obj["age"] }} filter test =========== upper test:{{ "must be upper"|upper }} word count for "hoge hage hige" = {{ "hoge hage hige"|wordcount}} func test ========= range(0,3) = {% for x in range(0,3) %}{{x}}{% endfor %} range(3,0) = {% for x in range(3,0) %}{{x}}{% endfor %} strlen("testtest") = {{ strlen("testtest") }} strlen("日本語") = {{ strlen("日本語") }} round floor of 1.5 = {{1.5|round("floor")|int}} round ceil of 1.5 = {{1.5|round("ceil")|int}} join(",", [1,2,3,4,5]) = {{ join(",", [1,2,3,4,5]) }} {% with long_list = [10,20,30,40,50,60,70,80,90,100] %} {% for row in slice(4, long_list) %} {% set y = loop.index %} {% for col in row %} {% set x = loop.index %} {{x}},{{y}} = {{col}} {% endfor %} {% endfor %} {% endwith %} filter tag test =============== {% filter upper %} must be upper {% endfilter %} list expr ========= {% for x in [1,2,3,4.5,"str"] %}{{x}}{% endfor %} {% for x in [] %}{{x}}{% endfor %} {{ join("-", [1,2,3]) }} {{ "{{" }} syntax test "is" ================ 6 is divisibleby 4 = {{ 6 is divisibleby(4) }} 6 is divisibleby 3 = {{ 6 is divisibleby(3) }} 6 is divisibleby 2 = {{ 6 is divisibleby(2) }} 6 is divisibleby 2 = {{ 6 is divisibleby 2 }} 6 is divisibleby 3 via func = {{ divisibleby(3,6) }} macro test ========== {% macro hoge_macro(i,j) %} {{i}},{{j}} {% endmacro %} {{ hoge_macro(10,20) }} {# at this point, delay_macro is not declared, but we can call it. #} {{ delay_macro(10,20) }} {% macro delay_macro(x,y) %} {{x}} {{ caller(1,2) }} {{y}} {% endmacro %} {% call(a,b) delay_macro("from", "to") %} inner text! args of call = {{a}},{{b}} macro name = {{delay_macro.name}} via caller = {{delay_macro.caller}} {% endcall %} {% macro subject_with_back(anchor, subject) %}

{{subject}}

{{ caller() }} back to top {% endmacro %} {% call subject_with_back("about", "about me") %} Hi, I'm a programmer living in Japan. {% endcall %} {% call subject_with_back("language", "favorite language") %} I love Scheme. {% endcall %} {% import "macro.tmpl" as testmac %} {{ testmac.test_macro(10,20) }} {% from "macro.tmpl" import test_macro, other_macro %} {{ test_macro(30,40) }} {{ other_macro(50,60) }} {% endblock main %} {% macro test_caller(x,y,z,age=120) %} this is test_caller age={{age}} class={{kwargs.class}} {{caller (x,y,z,kw_from_test_caller="yeah")}} {% endmacro %} {% call(a,b=100) test_caller(100,200,300,class="mytest") %} name={{test_caller.name}} caller={{test_caller.caller}} catch_kwargs={{test_caller.catch_kwargs}} catch_vargs={{test_caller.catch_vargs}} kw_from_test_caller={{kwargs.kw_from_test_caller}} {% endcall %} with statement test ==================== {% with foo = 10, hoge = 20 %} inner with foo = {{foo}}, hoge = {{hoge}} {% endwith %} after with foo = {{foo}}, hoge = {{hoge}} {% with %} {% set hige = 20 %} inner with hige = {{hige}} hige is defined = {{ hige is defined }} {% endwith %} after with hige = {{hige}} hige is defined = {{ hige is defined }} in expr test ============= 1 is in [1,2,3] = {{ 1 in [1,2,3] }} {% if 1 in [1,2,3] %} yes! 1 is in [1,2,3] {% endif %} {# raw statement test =================== {% raw %} this is not expanded -> {{hoge}} this is not for loop -> {% for x in long_list %}hahaha{% endfor %} {% endraw %} #} autoescape test =============== autoescape = true {% set script = "" %} {% autoescape true %} {{ script }} {% endautoescape %} autoescape = false {% autoescape false %} {{ script }} {% endautoescape %} obj literal =========== {% set person = {age:10, name:"taro"} %} person["age"] = {{ person["age"] }} person.age = {{ person.age }} person["name"] = {{ person["name"] }} person.name = {{ person.name }} eval ==== {% set source = "{% set evalue = 'from eval!' %}{{evalue}}" %} {{ eval(source) }}