Issue with contains modifier on modx 2.8

Hi there, Im trying to use a contains modifier as part of a getImageList call as follows

&tpl=@CODE:<li class="rd-nav-item active">[[+link]] == [+link:contains=http:then=is link!:else=isn’t]] <a class="rd-nav-link" href="#">[[+texto]]</a></li> ]]

But im getting things like

Subir a la cima - YouTube == isn’t

Pdta: backticks are where they are supposed to be, its just the formatting here that gets rid of them

What I’m missing?

I just fixed it by moving the CODE section no a new chunck, I guess something doesn’t get properly processed, can someone help me understand why this happens?

1 Like

What version of MODX are you on?

There is an issue with MODX 3.x and output modifiers with certain content.

HI just updated the title to make it more clear, its with modx 2.8

1 Like

Your tpl code does not look valid:

+link has only one [ before.

If you wrap the code with three backticks, it is formatted right in this forums.

&tpl=`@CODE:<li class="rd-nav-item active">[[+link]] == [[+link:contains=` http`:then=` is link!`:else=` isn’t`]] <a class="rd-nav-link" href="#">[[+texto]]</a></li> `]]
1 Like

I only can see a [ missing in the format in this part == [+ :

<li class="rd-nav-item active">[[+link]] == [[+link:contains= http:then= is link!:else= isn’t]] <a class="rd-nav-link" href="#">[[+texto]]</a></li> ]]

but I don’t understand what is the output you are looking for…

sometimes when you use output modifiers, the best wat is to put them into a $CHUNK to avoid weird behavior! :+1:

When you have nested tags, the MODX parser parses the inner tag first.

This can create problems with inline templates like this

    &tpl=`@CODE:[[+link]] == [[+link:contains=`http`:then=`is link!`:else=`isn't`]]`

because the parser tries to parse the tag [[+link:contains=`http`:then=`is link!`:else=`isn't`]] before the snippet tag [[getImageList? ... ]] is executed.

To avoid this, you can move the template code into a chunk (as you have done) or with getImageList you can also use tags with curly braces ({{...}}) in the inline template.

    &tpl=`@CODE:{{+link}} == {{+link:contains=`http`:then=`is link!`:else=`isn't`}}`

The MODX parser ignores these tags with the curly braces and the snippet getImageList converts them into proper MODX tags, before the template is used in the snippet.


Thanks a lot!, it makes it clear, and also fixes some other issues I was having with my extra

1 Like

the issue its the one explained by @halftrainedharry and basically I wanted to find if a user has entered an url or just a number on a TV so I can do the rigth process at the link (open new widnow if its external or open _self if it a internal page)

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”.