-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NFR] Switch block for Volt #13107
Comments
Good suggestion Would be great for example a role badge. But would need a way to break out the switch as well so that it doesn't cascade. I suggest a {% switch user.getRoles() %}
{% case "Owner" %}
<span class="label label-pill label-primary">Owner</span>
{% case "Admin" %}
<span class="label label-pill label-primary">Admin</span>
{% casebreak "Partner" %} // this should break the switch if matched
<span class="label label-pill label-primary">Partner</span>
{% default %}
Member
{% endswitch %} |
Thanks for creating this NFR for me :) |
Actually I prefer more something like: {% switch username %}
{# Each `case` statement can take multiple values to compare the variable #}
{% case "Jim" "Bob" "Joe" %}
Hello {{ username }}
{% case "Nik" %}
Hey hey {{ username }}!
{% default %}
{#
An optional `default` statement sets off the default output
if no matches could be found
#}
Who are you?
{% endswitch %} I need to investigate how to do this with |
Imho there shouldn't be endcase. Break should be just detected by next Also not sure about this multiple values for case. Is it possible in plain php? I don't think so, not sure if i saw syntax like this in any language/template. But it might be good thing. |
@Jurigag You "can" more or less with true/false.
|
@oscarmolinadev but that is contradictory, you might as well generate a series of if statements. the switch() is omitted how you are using it. Its like doing a switch cases have the functionality to have multiple condition match for the same code block switch($value) {
case 'jim':
case 'bob':
case 'joe':
echo 'Hello Multiple';
break;
case 'nik':
echo 'Hello Nik';
break;
default:
echo 'Hello anybody';
} |
@JABirchall Totally agree with you! My example is what you never should do. I see this ugly sh*** in my work one time. That's why I've put "can" :) In PHP you can make ugly things like that.. and |
I'm almost done worked version for php5 (without break still) so I need few days for php7 |
@oscarmolinadev Yea, if i see code like that in a PR at work I rip them a new one. It's not our policy to be rude to other employees when they do dumb shit like that but I just can't help my self xD. its something that infuriates me. |
@oscarmolinadev this is not purpose of switch really. For that you have |
Latest news: I have worked version for switch-case-break-default-endswitch for PHP 5 |
Implemented in 3.3.x branch |
New feature request, as per: https://forum.phalconphp.com/discussion/17035/feature-request-switch-for-volt
Intended behaviour
Allows for switch/case conditional rendering in Volt
Example
The text was updated successfully, but these errors were encountered: