Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TYPO3: Generate random variable in FLUID Template

I have three images in my FLUID template and would like to show one of these three images at random. Is there any method to do this in the FLUID template or is this impossible and I must go a other way?

I tried the TYPO3 extension "VHS" to generate a random number:

{v:random.number(minimum: 1, maximum: 3, minimumDecimals: 0, maximumDecimals: 0)}

In the frontend I see the generated number. But how can I set the random number to a variable to use it in a if-else-condition?

like image 586
Martin Avatar asked Feb 05 '26 09:02

Martin


2 Answers

This would also be possible with VHS

<v:iterator.sort subject="{images}" as="randomimages" order="RAND" />
like image 191
bschauer Avatar answered Feb 08 '26 23:02

bschauer


On TYPO3v7 with VHS installed:

{v:random.number(...) -> v:variable.set(name: 'newvariablename')}

On TYPO3v8 and above, or on Fluid standalone:

{v:random.number(...) -> f:variable(name: 'newvariablename')}

Then use the new variable:

<f:if condition="{newvariablename}" then="random number greater than zero" />
like image 25
Claus Due Avatar answered Feb 08 '26 23:02

Claus Due



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!