user1547410 user1547410 - 25 days ago 8
PHP Question

Phalcon Volt check_field with if else statement for checked

I have a checkbox im trying to build in Volt:

<input type="checkbox" class="myClass" data-size="small" data-type="{{ type.getType() }}">


So now i would normally write it like this

{{ check_field( 'class':'my class', 'data-size':'small', 'data-model-pk': ''~ AclGroup.id_group ) }}'


However i would like to do something like this:

<input type="checkbox" class="myClass" {% if AclGroup.flg_active == 1 %} checked="" {% endif %} data-size="small" data-type="{{ type.getType() }}">


But i have no idea how to do a statement inside
{{ }}


I tried breaking out of the
{{ }}{% %}{{ }}
and a bunch of other stuff but i cant find any documentation that covers it and nothing i tried works. Any ideas?

Answer Source

You could always leave it as you have given in your example - Volt is, at times, just a nice way to produce Html after all.

However, I would do this

{% if AclGroup.flg_acive == 1 %}
    {{ check_field( 'class':'my class', 'checked': "", 'data-size':'small', 'data-type': type.getType() ) }}
{% else %}
    {{ check_field( 'class':'my class', 'data-size':'small', 'data-type': type.getType() ) }}
{% endif %}

There is no way to use an if statement inside the echo - {{...}} - that I am aware of, so you need to have 2 echos and use and if-else instead.