Is possible to make an if statement in twig syntax and depending of the result close the html tag in a way or another. For example:
<button name="button" class="btn btn-warning"
{% if someCondition == false %}
> {#if is false close the button tag#}
<i class="fa fa-gift"></i><strong> Welcome<br />Present</strong>
{% else %}
disabled="disabled">{#if is true disable the button tag and then close#}
<i class="fa fa-gift"></i> Welcome<br />Present
{% endif %}
</button>
Thanks in advance.
-UPDATE-
Sorry I made a silly mistake, I was doing the right thing but in the wrong place that's why it did not reflected on my site. Thanks anyway (:
Your code looks right.
My way to do it :
<button name="button" class="btn btn-warning" {% if someCondition == true %} disabled="disabled" {% endif %}>
<i class="fa fa-gift"></i><strong> Welcome<br />Present</strong>
</button>
If you need to add the strong tag, you can add a class :
<button name="button" class="btn btn-warning" {% if someCondition == true %} disabled="disabled" {% endif %}>
<i class="fa fa-gift {% if someCondition == true %} strongClass {% endif %}"></i><strong> Welcome<br />Present</strong>
</button>
You can just do :
{% if someCondition == true %}
<button name="button" class="btn btn-warning" disabled="disabled">
<i class="fa fa-gift"></i><strong> Welcome<br />Present</strong>
</button>
{% else %}
<button name="button" class="btn btn-warning">
<i class="fa fa-gift"></i>Welcome<br />Present
</button>
{% endif %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With