2017-07-12 18 views
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で書くには、適切な方法を教えてください。

答えて

1
{% for i in 1..53 my_pattern == i ? currentpat = 'selected' : currentpat = '' %} 

forループの構文が無効です。

は、次のようなものがもしかして:

{% for i in 1..53 %} 
    <option value="{{ i }}" {% if my_pattern == i %}selected="selected"{% endif %}>{{ i }}</option> 
{% endfor %} 
+0

パーフェクト。ありがとう。 – HarnishDesign

関連する問題