duanbianweng5353
2016-09-21 07:32
浏览 33
已采纳

Symfony / Twig:表单小部件的内部ID?

I've to modify the radio_widget and would like to give the <label> and <input> the same ID, which should be unique for each pair.

Currently I'm using random(), but I'd prefer an internal counter, something like {{loop.index}} (Twig: for), to avoid conflicts.

{% block radio_widget -%}
    {% set id = random() %}
    <div class="radio">
        <label for="radio_{{ id }}">Label for {{ id }}</label>
        <input type="radio" id="radio_{{ id }}" {# ...#}/>
    </div>
{%- endblock radio_widget %}

Does anyone know a better solution?

Thanks in advance!

3条回答 默认 最新

相关推荐 更多相似问题