Documentation

Nenshi Template Language

1 Directives

1.1 Conditional Directives

1.1.1 t:if

<div>
  <span t:if="name">${name}</span>
</div>

renderd to:

<div>
  <span>Samuel</span>
</div>

t:if=" <expression>? "

The element is rendered true <expression>? is evalueated to true value.

1.1.2

The t:choose directive, in combination with the directives t:when and t:otherwise provides if...elsif...else or switch() case:... case:.. default:.. function. First matched t:when branch is rendered, or, if no py:when branch matches, the py:otherwise branch is rendered.

If t:choose directive is empty, nested t:when directives will be tested.

<div t:choose="">
  <span t:when="city == 'Tokyo'">ここは東京です。</span>
  <span t:when="country == 'Japan'">日本へようこそ!</span>
  <span t:otherwise="">Welcome!</span>
</div>

rendered to:

<div>
  <span>日本へようこそ!</span>
</div>

If t:choose directive contains an <expression>? the nested t:when directives will be tested for equality to the parent t:choose value.

<div py:choose="sex">
  <span py:when="'male'">男</span>
  <span py:when="'female'">女</span>
  <span py:otherwise="">unknown</span>
</div>

when sex=='female', rendered to:

<div>
  <span>女</span>
</div>

1.2 Loop

1.2.1 t:for

The element is repeated for every item in an iterable:

<ul>
  <li py:for="item in items">${item}</li>
</ul>

Given items=['foo', 'bar', 'hoge'] in the context data, this would produce:

<ul>
  <li>foo</li><li>bar</li><li>hoge</li>
</ul>

py:for=" <name>? in <expression>? "

<expression>? must return an Arrayref or an iterable value.