Alternate templates with migx

Hi, I work on ModX 3.0.4 pl and have MIGX 3.0.2 beta1 field but I’d like every other (even) item from it to have a different template so all odd (1st,3rd,5th…etc) to have template1 and every even (2nd, 4th, 6th…etc ) to have template2. Which are defined in chunks. I’ve tried this:

[[getImageList?
   &tvname=`Career_Path`
   &tpl=`@CODE:[[+_alt:is=`1`:then=`tpl1`:else=`tpl2`]]`
   &wrapperTpl=`outerTpl`
]]

but I get only “tpl1tpl2tpl1” as the output and if I try to change tpl1 or 2 with HTML structure it returns as array of values. How to achieve this seamlessly simple task? To use 2 different templates for odds and evens.

BTW. this one works fine I get my template HTML and my values etc just using one instead of 2 templates

[[getImageList?
   &tvname=`Career_Path`
   &tpl=`tpl1`
]]

Thank you for taking time to read this and eventually help me
@bobray @bruno17

Use this instead:

[[getImageList?
   &tvname=`Career_Path`
   &tpl=`tpl1`
   &tpl_n2=`tpl2`
   &wrapperTpl=`outerTpl`
]]

&tpl_n2 → the number at the end is the divisor. In this case tpl2 is used for every second row.

1 Like

@halftrainedharry Thank you so much for taking time to look at this issue. I’ve tried what you have proposed but I’m getting arrays as output. This happened to me before in some of the variations and it looks like this. Do you have any ideas why I’m getting this instead of templates populated with data.

Array
(
    [MIGX_id] => 1
    [image] => img/pic1.png
    [title] => Pipefitters
    [content] => Local 525 Pipefitters are the best in the business when it comes to the installation and repair of both high and low pressure pipe systems that are used in manufacturing, in the generation of electricity and in the heating and cooling of buildings. They also install automatic controls that are increasingly being used to regulate these systems.
    [link1] => 7
    [link2] => 33
    [_alt] => 0
    [_first] => 1
    [_last] => 
    [idx] => 1
    [property.tvname] => Career_Path
    [property.tpl] => tpl1
    [property.tpl_n2] => tpl2
)
Array
(
    [MIGX_id] => 2
    [image] => img/pic2.png
    [title] => Plumbers
    [content] => Our contractors and craftsmen provide quality installation, service and repair of commercial and residential plumbing systems. We build and service plumbing systems that deliver pure drinking water, and safe sanitary plumbing systems. We service and install water and gas piping systems and fixtures in homes, commercial enterprises and other institutions.
    [link1] => 6
    [link2] => 33
    [_alt] => 1
    [_first] => 
    [_last] => 
    [idx] => 2
    [property.tvname] => Career_Path
    [property.tpl] => tpl1
    [property.tpl_n2] => tpl2
    [_tpl] => 
)
Array
(
    [MIGX_id] => 3
    [image] => img/pic3.png
    [title] => Service Technicians
    [content] => Over the last twenty years, a substantial increase in the number of nonunion air conditioning and refrigeration contractors has unleashed a fierce and destructive level of competition on the entire industry. Today, consolidated HVAC-R contractors and utility subsidiaries entering into non-regulated markets have acted to perpetuate this.
    [link1] => 3
    [link2] => 33
    [_alt] => 0
    [_first] => 
    [_last] => 1
    [idx] => 3
    [property.tvname] => Career_Path
    [property.tpl] => tpl1
    [property.tpl_n2] => tpl2
)

do you have created the chunks with name tpl1 and tpl2?

1 Like

Yes I did, but you were right. name was tpl_1 instead of tpl1 :slight_smile: and now it’s working properly. Thank you so much, I knew that this was not something complicated, and I was missing proper syntax!!! Thank you very much for your help. Just one question though, if I wanted to have more templates like 3 or something would syntax in that case be like this:

[[getImageList?
   &tvname=`Career_Path`
   &tpl=`tpl1`
   &tpl_n2=`tpl2`
   &tpl_n3=`tpl3`
   &wrapperTpl=`outerTpl`
]]

???

This combination doesn’t make much sense. tpl3 is used for every third item, tpl2 for every second one. This gives you this irregular pattern than won’t be useful:

index template
1 tpl1
2 tpl2
3 tpl3
4 tpl2
5 tpl1
6 tpl3
7 tpl1
8 tpl2
9 tpl3
10 tpl2
1 Like

I understand now thank you so much!

if you need special tpls for each row, you can do it with

&tpl=`@SNIPPET:myTplSnippet`

here you can return the tpl - chunkname depending on the idx

1 Like

You helped a lot thank you!