Issues with :notempty

I have a number of divs in my templates that use :notempty tests to skip or include that section. They have all been working beautifully except one: Hotels.

I have included the code of one of the working sections and the misbehaving hotel section:

<!-- if GenOne has value -->
[[*GenOne:notempty=`
<div id="div7" class="textbox vert2horz whtbck">
  <div class="tr50">
    [[*GenOne]]
  </div>
  <div class="tr50">
    [[*GenTwo]]
  </div>
</div>
`]]

<!-- if Hotels has value -->
[[*Hotels:notempty=`
<div id="div6" class="whtbck">
  <h3 class="red title4">Handpicked Inns for a Great Sleep</h3><br>
  [[*Hotels]]
</div>
`]]

If the TV GenOne has content, then the divs and content get inserted as expected. But if the TV Hotels has content, then only the content of Hotels is shown, the div wrapper and H3 are gone. It is replacing everything with the TV value, not just the [[*Hotels]] tag.

I can not see any difference in the codes and am totally stumped as to why the rest work but not hotels. We are inserting a single div with unordered list to create a slider.

There are more if :notempty sections both before and after this one in the templates.

I am running MODX 3.1.1 on an apache server with MySQL, everything is up to date. We have no extras or modifications, just the basic install.

Strange the code looks good to me but the best way to do this would be:

[[[[*Hotels:notempty=`$HotelsChunk`]]]]

HotelsChunk

<div id="div6" class="whtbck">
  <h3 class="red title4">Handpicked Inns for a Great Sleep</h3><br>
  [[*Hotels]]
</div>

This way the content of HotelsChunk will only be parsed if needed.

See: Tags as the Result or How Conditionals are like Mosquitoes

Thanks that does seem to do the trick. Not sure if I need to do that to all the :notempty conditionals, though will probably leave well enough alone.

Does the value of the TV “Hotels” on this resource contain any special characters (maybe a backtick ` or opening square brackets [[ without the corresponding closing ones ]] ) that would explain why it throws off the MODX parser?

1 Like

Thanks halftrainedharry. Your answer got me looking and sure enough there were backticks hidden in a comment. Got rid of them and everything now works with the original code.

2 Likes

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