I have a template with many TVs.
For subtitles I use a text TV, the output ist
[[*mytexttv:notempty='<h2>[[*mytexttv]]</h2>']]
(in original code there are backticks, not apostrophes)
It works with regular text, but a line ending with a question mark kills the output. On the frontend I see only a backtick and the following output is gone. Question mark is the only character which produces this behaviour. I tried other modifiers to test if the TV is empty or not but the result is always the same.
Any ideas?
Environment
MODX 2.8.1, Apache 2.4.43 (Unix), MySQL 5.7.32-log, PHP 7.4.13
Does the value work if you just use [[*mytexttv]] with the ? in the value but fails when used inside an OM or in the If snippet? Are you able to look in the DB and see what’s in the field for the TV? It feels to me like there could be some strange character there.
It works stand-alone without a wrapping snippet or an output modifier.
In the DB the field is filled with the correct value “Test?”, no strange characters, no more characters than these.
This is the complete code, reduced to the essential components. The TV (type text) is nested in an IF snippet call:
[[IF? &subject=`[[*texthead]][[*textblock]]` &operator=`notempty` &then=`<div class="text">
[[*texthead:notempty=`<h2>[[*texthead]]</h2>`]]
[[*textblock]]
</div>`]] <!-- shows nothing but a backtick
This construct crashes the content of this block itself and all following content. (There are more components, but this is the relevant part.)
If I set the texthead TV alone in an additional line I can see the correct output in frontend but not the output of the TV with output modifier.
[[IF? &subject=`[[*texthead]][[*textblock]]` &operator=`notempty` &then=`<div class="text">
[[*texthead]]
[[*texthead:notempty=`<h2>[[*texthead]]</h2>`]]
[[*textblock]]
</div>`]] <!-- shows "Test?" from the stand-alone TV followed by nothing -->
And? I got the texthead-Value twice and correct as “Test?” No chrashes, no missing content. Seems there is a conflict with the IF snippet.
Is there an other solution to test if multiple TVs are not empty to put out a content construct? I use the snippet to test if one of the elements is not empty, then the whole block may be output. If all elements are empty, nothing should be output.
It seems the parser gets confused with the ? (probably because the ? character is used to separate the snippet-name from the properties).
Maybe but it shouldn’t do that. It’s a regular text character within the TV.
I’d just write my own snippet.
Thanks for the hint. I prefer to use on-board resources if possible. To many self-written snippets are hard to maintain and I’m not a not a gifted programmer
@bruno17 Thanks but the block is more complex in real configuration (plus image, alt text, optional image legend, image position, width of the block and an additional textarea TV for optional chunks/snippet calls).
Yes, it would be possible to build the blocks (5 optional blocks on every page) with MIGX.
Nice idea …
What about the render performance with a MIGX construct? Is it fast enough compared to my solution for 5 blocks with all the TVs an the output modifiers?
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”.