Output modifier on modx placeholder is not working

2k views Asked by At

I have this code in a template

[[+isShowMore:is=`1`:then=`show more`:else=`no`]]

It is printing no. But it should show show more as placeholder isShowMore is set to 1 by this line of code in a snippet.

$modx->setPlaceHolder('isShowMore', 1);

Also checked by this code

[[+isShowMore]]
[[+isShowMore:is=`1`:then=`show more`:else=`no`]]

[[+isShowMore]] is printing 1 but the line with output modifier showing no.

Any clue what is wrong here? I am using modx revolution 2.2.8 traditional.

Similar issue is also posted in modx forum. http://forums.modx.com/thread/85150/output-filter-on-placeholder-problem#dis-post-469615

5

There are 5 answers

1
Sean Kimball On

give the eq modifier a try:

[[+isShowMore:eq=`1`:then=`show more`:else=`no`]]
0
orbitory On

Not sure why this doesn't work in your case so I recommend you do it with a snippet.

[[EvalIsShowMore? &val=`[[+isShowMore]]`]]

in EvalIsShowMore snippet put something like

<?php

if($val){
  echo 'something';
}else{
  echo 'nothing';
}
1
Kristian Sandström On

Are you doing that conditional inside another conditional somehow? Nesting conditionals usually cause this type of weird problem. Have you tried calling both your snippet and the placeholder output uncached?

I've also experienced this several times and there doesn't seem to be an obvious cause, some unknown magic in the modx output conditional logic. Experience has taught me to simply try to avoid using them as much as I can.

It's ugly but perhaps you could work around your problem by placing whatever you wish to output in the actual placeholder and then just printing the placeholder as it is.

0
NightFox On

Hm, probably your placeholder is located above snippet!  In Modx output occurs at the last moment, but the logic works consistently (cascade). 

Here's an example of how to do: 

 [[+isShowMore]]
 [[!yourSnippet]]
 [[+isShowMore:is=`1`:then=`show more`:else=`no`:toPlaceholder=`isShowMore`]]

another example: 

 [[+snippet_placeholder1]]
 [[!snippet]]
 [[+snippet_placeholder1:add=`[[+snippet_placeholder2]]`:toPlaceholder=`snippet_placeholder1`]]
2
Jon Onstott On

I had this problem; my page was using a template that had [[*content]]. Changing that to [[!*content]] to get rid of caching solved my issue.

FYI, my snippet is being called with ! so that its output isn't cached either.