GetImageList: Retrieve Every Other Entry?

Is there a way to have GetImageList call on every other entry in a MIGX template variable?

1 Like

From the docs it looks like this will work

	[[+_alt]]      returns 1 every second row


Thank you, I completely missed that.

1 Like

No worries, that’s the place to start when you want to do something, just fyi

Keep in touch! This site is really building up some good support threads

As a general tip, with many snippets you get access to an [[+idx]] or [[+index]]-like placeholder that contains the number of the result in the set. Some start at 0 while others start at 1, but regardless you can use the modulus (or mod) output filter to also get the Nth result.

[[+idx:mod=`2`:eq=`0`:then=`second result`:else=`not a second result`]]

For indexes starting at 0, it’s easy to add 1 first:

[[+idx:add=`1`:mod=`2`:eq=`0`:then=`second result`:else=`not a second result`]]

If there’s already a placeholder like [[+_alt]] available, using that will save you some processing, but when it’s not, use the modulus.


I did see mod used a few places online, but I never knew what it meant as I can’t seem to find it in the documentation anywhere. Can you clarify its use? Is it simply the equivalent of nth, like is this one of the nth records retrieved?

1 Like

In this case mod is short for modulus. It is listed in the output filter documentation, search for “modulus” on the page.

The modulus is a mathematical concept. If you take an input number (e.g. 10) and provide the modulus (e.g. 4), then the return value is calculated by fitting the number 4 into the input as many times and possible, and returning how much is left. So 4 fits twice in 10, leaving a number of 2.

This is probably the simplest video showing a more visual explanation about the modulus:

With a modulus of 2, that will always either fit exactly, returning 0, or there’s 1 left, which makes it useful for odd/even type things. Eg:

1 = (0 x 2) + 1
2 = (1 x 2) + 0
3 = (1 x 2) + 1
4 = (2 x 2) + 0


This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.