Usage of v:or for multiple conditions

Shows how to use the v:or ViewHelper instead of multiple f:if conditions to select the first value that is not empty and use or output it. Explains how the ViewHelper can be used together with f:if (and any other condition ViewHelper) or as an alternative to it.

Description Usage of v:or for multiple else-style conditions
Author NamelessCoder
Creation date 2014-08-24T03:27:23.000Z
Extensions
  1. FluidTYPO3.Vhs
Tags
  1. ViewHelpers
Files
  1. Or.html
<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>
view raw Or.html hosted with ❤ by GitHub