URL

http://twig.sensiolabs.org/

構文

変数

{{ foo.bar }}
{{ foo['bar'] }}

コメント

{# ... #}

For 文

<h1>Members</h1>
<ul>
  {% for user in users %}
	 <li>{{ user.username|e }}</li>
  {% endfor %}
</ul>
{% for i in 0..10 %}
  * {{ i }}
{% endfor %}
{% for letter in 'a'..'z' %}
  * {{ letter }}
{% endfor %}
{% for letter in 'a'|upper..'z'|upper %}
  * {{ letter }}
{% endfor %}

ループ内特別変数

loop.indexThe current iteration of the loop. (1 indexed)
loop.index0The current iteration of the loop. (0 indexed)
loop.revindexThe number of iterations from the end of the loop (1 indexed)
loop.revindex0The number of iterations from the end of the loop (0 indexed)
loop.firstTrue if first iteration
loop.lastTrue if last iteration
loop.lengthThe number of items in the sequence
loop.parentThe parent context

if 文

{% if users %}
  <ul>
	 {% for user in users %}
	   <li>{{ user.username|e }}</li>
	 {% endfor %}
  </ul>
{% endif %}
{% if kenny.sick %}
	 Kenny is sick.
{% elseif kenny.dead %}
	 You killed Kenny!  You bastard!!!
{% else %}
	 Kenny looks okay --- so far
{% endif %}

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2011-09-21 (水) 11:26:25 (2980d)