Global Random Keyword in Asset Listing


(N Wallis) #1

Hi there, 

 

I am using the following global keyword as part of the HTML for an Asset Listing I am using:

 

%globals_random_1_3%

 

The asset listing is rendering a JSON data source and I want to append a random number in my HTML.  My JSON currently has 3 items and the problem I have having is that each JSON item is assigned the same number - which leads me to believe that this keyword will generate a random number for each page load, not each asset iteratoin. Is that correct?  If so, is there anyway I can get around this?

 

Cheers, 

Nathan


(Joel Porgand) #2

Heh, looks like you're right. Without actually looking at the code I'd guess the globals keyword is processed prior to the individual list items being rendered. For most globals keywords this makes sense (as they're going to give the same result, so why bother process it multiple times) but for the random keyword it's a bit counter-intuitive. 

 

What are you actually trying to achieve?


(N Wallis) #3

Hi JP. 

 

Part of the requirements for a particular task I am working on is to assign a random CSS style to each of the JSON elements that I am rendering.  So I was just using it for that.   I was trying to do it all inside Matrix and avoid any client side monkeying... 


(Nic Hubbard) #4

Could you just use the asset position instead?


(N Wallis) #5

The number of items in my JSON feed might be more than 3 - I should have mentioned that.    Nice to know about anyway.  I will give them a try in case they will work for a varying number of elements


(N Wallis) #6

Hi.. 

 

Based on your asset position idea, I tried the following and I think that will get me out of trouble..  I couldn't see the position formats working with a dynamic number of elements. 

 

%asset_position^modulo:3%

 

Thanks for pushing me in the right direction.