MODX Revolution 2.3.1
I like to use MDOX: The Officil Guide (MTOG) for information and, if the topic is covered, I usually can work things out for myself. However I have run into a problem and I don't know whether there is a defect (bug) or I have miscoded/misunderstood something.
The particular topic is "Replacing Conditional Modifiers with a Snippet" (pg 280ff).
There is a place-holder being set in the Registration process (using the Login package). The particular place-holder is an error message [[+error.username]]. There are others, but I'm using this as an example.
Now that place-holder is either "empty" or a text string. When a text string is set as the value, it is now wrapped in HTML tags (good!). Now all the examples of setting up a Registration form TPL chunk that I have seen embed the error-message place-holder in HTML tags such as <span class="xxx"> and </span>. I don't happen to like generating empty HTML code that does nothing useful; however, that is not an option as the HTML I want to wrap the error-message in results in extraneous white-space when it is "empty'.
So, the solution seems to be to have a Snippet test the value of the place-holder and return the appropriate "output" — an empty string or the error-message wrapped in HTML markup. So we have the following example code in MTOG:
/* Code for the YesNo Snippet */
if ($value) {
$output = 'Yes';
} else {
$output = 'No';
}
return $output;
Now $value is simply a tag (it happens to be a resource field in the example) and the code implies it can successfully check
the actual value after the tag passed as a property has been evaluated.
So fine, I created the following code (in a snippet):
if (empty($value)):
return '';
else:
return $beginHtml . $value . $endHtml;
endif;
However, after a lot of experimenting and testing, it became abundantly clear that
the unevaluated tag is what the snippet code is "seeing". It always returns the HTML code — sometimes with nothing in it; sometimes with an error message (when appropriate).
The snippet invocation looks like this (if it helps understand what is happening):
[[WrapNotEmpty?
&beginHtml=`<br /><span class="error">`
&value=`[[+error.username]]`
&endHtml=`</span>`
]]
Any ideas?