In one of my NEOS Templates I try to solve the simple task of generating a random number (within a specified range) and store it into a variable for later usage.
Since none of the default view helpers offers such a feature I developed my own view helper, which expects a min and max value. Internally the view helper uses php's rand($min, $max)
.
The following example is working in my template:
site:RandomNumber(0, 17)
As expected this outputs a random number. However now I need to store the result into a variable, since I have to use it more than one time.
I came across fluids alias-view-helper:
<f:alias map="{number: 33}">
The number is {number}
</f:alias>
This results in:
The number is 33
Now I want the number not to be 33, but the result of my RandomNumber
-view-helper.
I tried things like:
<f:alias map="{number: {site:RandomNumber(0, 17)}}">
The number is {number}
</f:alias>
This however throws an Exception saying:
The argument "map" was registered with type "array", but is of type "string"
in view helper "TYPO3\Fluid\ViewHelpers\AliasViewHelper"
The docs of the f:alias
view-helper say accepted values are other view-helpers, but they never give any examples on that.
Am I completely wrong with this approach? Is it simply not possible to assign a simple variable within a fluid-template?
Further information: I do have a slider on the website, which should start with a different slide on (almost) every page-load. So I need to grab this random slide-number, which I have to refer to in the slider markup several times.