MIGX in MIGX - how to iterate and compare arrays in the getImageList function

Hi, I think it’s simple and I don’t know how to do it.

I have a MIGX, named “speaker”, which has among other fields such as “name”, “image”, etc. I also have a second MIGX named “program” where I have a field called “speaker” which contains the “name” from the MIGX “speaker”. The name field can be a string or an array of strings:

[{"MIGX_id":"1","time":"09.30","speaker":["speaker1","speaker2"]},{"MIGX_id":"2","time":"11.00","speaker":"speaker3"}]

  1. how can I iterate an array in a template? Do I need to write a snippet for this or is there a simpler way?

  2. how can I compare the array “speaker” in “where”? I try something like this but it doesn’t work:

[[getImageList?
   &tvname=`speaker`
   &tpl=`@CODE:<img src="[[+image]]" alt="" class="is-loading">`
   &where=`{"name:find_in_set":"[[+speaker]]`"}`
   &docid=`[[*id]]` 
]]

Maybe try using inarray instead of find_in_set when [[+speaker]] is the array:

&where=`{"name:inarray":"[[+speaker]]"}`
// or possibly
&where=`{"name:inarray":"[[+speaker:replace=`||==,`]]"}`
1 Like

Unfortunately it didn’t help. When I want to print the variable “speaker” by using [[+speaker]] then:

for
{"MIGX_id":"1","time":"09.30","speaker":["speaker1","speaker2"]}
I get: speaker1speaker2
as if the JSON array was converted into a string without any delimiter and maybe there is a problem here.

What “Input TV type” are you using for the speaker field in the “program” MIGX config?

If you’re using an actual TV for the speaker field, try changing the “Output Type”.

“speaker” is Input TV type listbox-multiple
image

Input Option Values @CHUNK speakerSelect
image

Chunk speakerSelect

[[getImageList?     &tvname=`speaker`     &tpl=`@CODE:[[+name]]`     &limit=`0`     &outputSeparator=`||` ]]

In the outer call to getImageList, use &processTVs=`0` so that the speaker array doesn’t get processed.

[[getImageList?
   &tvname=`program`
   &processTVs=`0`
   ...
]]
1 Like

Oh yes, it works! Once again you have a big beer with me bro!

It works with

[[!getImageList?  &tvname=`program` &tpl=`tpl_program` &processTVs=`0`]]

In the template tpl_program

[[getImageList?
   &tvname=`speaker`
   &tpl=`@CODE:<img src="[[+image]]" alt="" class="is-loading">`
   &where=`{"name:inarray":"[[+speaker:replace=`||==,`]]"}`
   &docid=`[[*id]]` 
]]

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.