4

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 (:

3
  • the only thing/difference is that you want to do is disable the button if the condition is false? Commented Mar 16, 2016 at 8:51
  • 1
    I will delete the question (: I made a mistake in the place I used this and thats the reason i did not see it reflectad in my site. Thanks anyways. Commented Mar 16, 2016 at 8:54
  • hi omar don't worry about, have you solved? Do you want to update your question? Commented Mar 16, 2016 at 9:10

1 Answer 1

4

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 %} 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.