Use of logical operators in Fluid-Template

Hey again :relieved:,
sorry for all the crazy simple questions. But once again, I can’t find an answer in references or with friend google:
I would like to check more than one submitted value like:

<f:if condition="({imageSmall} || {retinaImageSmall})">
		<f:then>
			...
		</f:then>
		<f:else>
			<f:if condition="{image}">
				...
			</f:if>
		</f:else>
	</f:if>

Tried it with and without wrapping bracket, also ||, OR, or, &&, AND, and, … always the same:
ERROR:

An exception was thrown while Neos tried to render your page
Cannot cast object of type "TYPO3\Flow\Persistence\Doctrine\Proxies\__CG__\TYPO3\Media\Domain\Model\ImageVariant" to string.

//OR
An exception was thrown while Neos tried to render your page
A boolean expression has more than tree parts.

Maybe there is a fault in my code, or if Fluid can not do so as Twig, someone knows a workaround?
Would be great. The Reference https://docs.typo3.org/typo3cms/ExtbaseGuide/Fluid/ViewHelper/If.html only show simple conditions, I guess, or I’m really blind :sunglasses:.

That is a feature that is not yet in Neos Fluid. The documentation you are referring to is from extbase, which was originally a port of Flow+Fluid to Typo3 CMS. It has since developed a bit of an own pace.

Regarding your issue: The recommended way to deal with this is to actually do complex logic inside your models or the controller. As a fallback you can also write custom viewhelpers, though that should be left for very specific cases.
Optimally, a view should not contain too much logic.

As for boolean AND there is at least a hackish work-around, by using array comparison:

<f:if condition="{0: someValue, 1: someOtherValue} == {0: true, 1: 'magicValue'}">

will be equivalent to someValue == true && someOtherValue == 'magicValue'.

1 Like

Thank you for information @aberl,

Also for your work-around. Great to know. But now that I know, there is not a lightweight template-solution, I can do it for an «OR» also in prototype (more MVC-like I guess)
So more complex logic is out of fluid-Template.

#Image.ts2
hasSmallImages = ${(q(node).property('imageSmall') || q(node).property('retinaImageSmall')) ? TRUE : FALSE}
# Image.html
<f:if condition="{hasSmallImages}">
	<f:then>
	...
	</f:then>
	<f:else>
		<f:if condition="{image}">
		...
		</f:if>
	</f:else>
</f:if>
2 Likes

Your are right, keep your template a simple a possible and use TS/EEL to prepare the data that your templates need.

A template need to be understandable by people without much coding knowledges.