Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to properly extend twig ternary statement?

I am trying to include a modal in a new place, and in order to direct a proper controller for a template, I am distinguishing them by different values passed from 3 other templates – which, in my case, are:

{% include '@path' %}
{% include '@path' with { foo: 'a' } %}
{% include '@path' with {foo: 'b'} %}

And these are conditions in the invoked template which I came up with to distinguish which controller should be used right now

Originaly, it was just:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

{% set controller = foo | default('') == 'a' ? 'ctrl' : 'ctrl2' %}

and it worked properly.

{% set controller = foo | default('') == 'a' ? 'ctrl' : 'b' ? 'ctrl' : 'ctrl2' %}

But now, after modification I can’t manage to make it return the ‘ctrl2’ value, so modal won’t display.

Can you help? Is this even sufficient amount of information to describe this problem?
Thank you.

>Solution :

You forgot one element in your second condition :

{% set controller = foo | default('') == 'a' ? 'ctrl' : (foo | default('') == 'b') ? 'ctrl' : 'ctrl2' %}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading