[SOLVED] Fluid Random Image

Hey guys,

Is there a way (in fluid) to output a content in a for loop at random? One item from {assets}?

I have tried this in fusion with (Asset List in NodeTypes)

prototype(Site:RandomImage) < prototype(Content) {
templatePath = 'resource://My.Site/Private/Templates/FusionObjects/RandomImage.html'
randomImage = ${q(documentNode).property('assets').random().get(0)}

}

Thx!

There is no default “random” FlowQuery operation, but you can of course implement one yourself. You will probably need to make the Fusion object uncached though.

Thank you Bastian!

I think “random” already exists.
I have found this:

${Array.random(q(site).children('assets').children().get())}

but how can I do this with property (Assetlist).

Random just “Picks a random element from the array”, but you might be able to use shuffle instead:

prototype(Neos.NodeTypes:AssetList) {
	assets = ${Array.shuffle(q(node).property('assets'))}
	@cache {
		# cache for one hour
		maximumLifetime = '3600'
	}
}
2 Likes

It works! Thank you Bastian!

1 Like