User:Cpiral/sandbox

Extension:ParserFunctions process strings, strings directly or strings indirectly by way of parameters (or transclusions, or variables, or other parser functions). Parameter 1 returns the string when not indicated by the user of a template, which is probably not what you want in a parser function. Rather than depending on the user to indicate the parameter is empty, apply your own default. A lone pipe symbol ("|") ensures proper handling for when parameter is or is not indicated.

We'll use #if to represent the situation of parameters in parser functions. With #if the default test string should be null, because the truth of an #if function is whether or not there is content in the test string.


 * Comparison

Although named parameters pass in whitespace differently from positional parameters, there is no whitespaces that counts as content in a test string. When determining whether or not informational content is intentionally passed, only the second usage , , makes sense, because   becomes (interpolates to) an actual string.

When using, #if returns the same result whether the user gives no indication,, or merely some indication:. Use #ifeq when you need to determine which occured.

 

Furthermore a similar trick is needed and implemented in a wrapper in those rare occasions when a "sensitive" parameter cannot have a null value automatically assigned to it (when the user indicates the parameter but does not give it a value with actual content). The technique works with both named and positional (numbered) parameters.

A wrapper template uses the same set of parameters as the wrapped template with the sensitive parameter, but it handles the sensitive parameter by changing its name (to anything meaningless and inconsequential) as follows:

The wrapped_template receives the normal_parameter and any content it containts as usual, or as explained above, with a null value if it is either not indicated at all, or merely indicated (with no content given to it).

The wrapped_template receives a sensitive_parameter only when it has content. If the sensitive parameter is in any way indicated by the user, but without giving it any content, the test string to the #if is a null character (nothing), so it reads sensitive_parameterNULLNOTALLOWED = otherwise it reads sensitive_parameter = and the content is passed through to the wrapped template.