请问我怎样才能用树枝复选框做如下事情
<input type="checkbox" name="checkbox">
{% if checkbox is checked %}
#do_it
{% else %}
#do_that
{% endif %}
请帮帮我
复选框返回字符串值。
{% if node.field_mycheckbox.value == '1' %}
<p>print 1</p>
{% else %}
<p>print 0</p>
{% endif %}
控制器:
$dispo = $mezzo->getAuDisponibile ();
// table column AuDisponibile is boolean
...
...
return $this-render ('anagrafiche/automezzi.html.twig', ['dispo' => $dispo]);
模板:
{% if dispo %}
<input input type='checkbox' name="idisponibile" value="SI" checked>
{% else %}
<input input type='checkbox' name="idisponibile" value="SI">
{% endif %}
例如,您可以检查是否检查了表单字段,
{% if form.field.children.KEY.vars.checked %}
Do something here
{% endif %}
在循环中使用它。
{% for child in form.field %}
<input type="checkbox" name="checkbox" {{ child.vars.checked == true ? "Checked" }}>
{% endfor %}
或
<input type="checkbox" name="checkbox" {{ form.field.children.KEY.vars.checked ? "Checked" }}>
KEY 是数组键。
试试这个:
{% if checkbox.checked %}
而不是这个:
{% if checkbox is checked %}