0
twigでPHPコードを変換しようとするとこのエラーが発生します。'値の予期しないトークン "名前"
Fatal error: Uncaught exception 'Twig_Error_Syntax' with message 'Unexpected token "name" of value "my_pattern" ("end of statement block" expected) in...
PHPコード:
<select class="form-control" name="my_pattern">
<?php for ($i = 1; $i <= 53; $i++) {($my_pattern == $i) ? $currentpat = 'selected' : $currentpat = ''; ?>
<option value="<?php echo $i; ?>" <?php echo $currentpat; ?>><?php echo $i; ?></option>
<?php } ?>
</select>
私は小枝ファイルに次のようにしてみてくださいしています。
<select class="form-control" name="my_pattern">
{% for i in 1..53 my_pattern == i ? currentpat = 'selected' : currentpat = '' %}
<option value="{{ i }}" {{ currentpat }}>{{ i }}</option>
{% endfor %}
</select>
上記のコードをtwigで書くには、適切な方法を教えてください。
パーフェクト。ありがとう。 – HarnishDesign