反復で現在の要素への参照を取得するにはどうすればよいですか?
{{#my_array}}
<p>{{__what_goes_here?__}}</p>
{{/my_array}}
明らかなことを見落としていることを願っています。
仕様の変更ログによると、仕様の.
v1.1.0 で暗黙の反復子 ( ) が追加されました。少なくとも v1.1.0 を実装するすべての Mustache ライブラリは、これをサポートする必要があります。
{{#array_of_strings}}<li>{{.}}</li>{{/array_of_strings}}
ソースコードよりhttps://github.com/bobthecow/mustache.php
/**
* The {{%IMPLICIT-ITERATOR}} pragma allows access to non-associative array data in an
* iterable section:
*
* $context = array('items' => array('foo', 'bar', 'baz'));
*
* With this template:
*
* {{%IMPLICIT-ITERATOR}}{{#items}}{{.}}{{/items}}
*
* Would render as `foobarbaz`.
*
* {{%IMPLICIT-ITERATOR}} accepts an optional 'iterator' argument which allows implicit
* iterator tags other than {{.}} ...
*
* {{%IMPLICIT-ITERATOR iterator=i}}{{#items}}{{i}}{{/items}}
*/
コードから少し離れて、Ruby はダック タイプであることを思い出しました。私の配列は文字列だったので、必要なのは次のとおりです。
{{#my_array}}
<p>{{to_s}}</p>
{{/my_array}}
他の誰かの時間を節約することを期待して、この質問をここに残します。