在我的服务中,我返回一个如下所示的数组:
$array = [
'bible_anagram_word' => $result->getBibleAnagramWord(),
'word_1' => $result->getWord1(),
'word_2' => $result->getWord2(),
'word_3' => $result->getWord3(),
...
'word_22' => $result->getWord22(),
'word_23' => $result->getWord23(),
'word_24' => $result->getWord24(),
'word_25' => $result->getWord25(),
'Bible_verse_reference' => $result->getBibleVerseReference(),
'Bible_verse_text' => $result->getBibleVerseText(),
'Bible_translation' => $result->getBibleTranslation(),
];
如何在此 for 循环中表示 document.word_##?
{% for i in 1..25 %}
{{ document.word_ ~ i|slice(0,1) }}
{% endfor %}
在 PHP 中,这段代码是:
substr ( $this->document['word_'.$i] , 0 , 1 )
我不成功的尝试包括:
- {{ document.word_ ~ i|slice(0,1) }}
- {{ (document.word_ ~ i)|slice(0,1) }}
- {{ 'document.word_ ~ i'|slice(0,1) }}
最佳答案
关于symfony - 使用 for 循环表示 Twig 中的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31507881/