PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, March 12, 2022

[FIXED] How to properly extend twig ternary statement?

 March 12, 2022     php, symfony, twig     No comments   

Issue

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:

{% 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' %}


Answered By - jean-max
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing