Created
August 24, 2014 03:27
-
-
Save NamelessCoder/61b88932125b6aecbb5a to your computer and use it in GitHub Desktop.
Usage of v:or for multiple else-style conditions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div xmlns:v="http://typo3.org/ns/FluidTYPO3/Vhs/ViewHelpers" | |
xmlns:f="http://typo3.org/ns/fluid/ViewHelpers"> | |
<!-- v:or can be used for long chains of conditions where the first | |
not-empty value gets used --> | |
<!-- If {person} for example can have three different email addresses' | |
but you only wish to display one of them: --> | |
Email: {person.workEmail -> v:or(alternative: person.secretaryEmail) -> v:or(alternative: person.homeEmail)} | |
<!-- Which displays one of the three email addresses with priority | |
to the workplace email, secondary priority to a secretary's | |
email and if neither is defined, person's home email --> | |
<!-- Can also be used as a chain after any other condition to use | |
the "alternative" value if neither condition case outputs content --> | |
{f:if(condition: person.workEmail, then: person.workEmail, else: person.secretaryEmail) -> v:or(alternative: person.homeEmail)} | |
<!-- Which is exactly the same as the above example with two v:or tags | |
but as you can see, takes less space and is easier to read --> | |
<!-- Can also be used to deliver default images when no image exists: --> | |
<f:image src="{myObject.imageFile -> v:or(alternative: settings.defaultImageFile)}" alt="" /> | |
<!-- All in all, a more compact alternative to multiple f:if tags which | |
is ideally used as inline syntax in chains. --> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment