01152: Display empty and undefined variables as null

Summary: Display empty and undefined variables as null
Created: 2009-11-14 13:43
Status: Closed - added for 2.2.14
Category: Bug
From: simon
Assigned:
Priority: 544
Version: 2.2.7
OS: any

Description: When variables from include directives and pagelist directives are used in a wiki page, but are undefined, or incorrectly defined (see test page) they should display consistently as do page variables and page text variables.

These include and pagelist variables should display as null where not defined or defined as empty ("Avar=").

See

See also

This is not a bug, it is specifically designed to be this way. These {$$variables} are designed to be replaced by a value when it is found, and to stay as is, if there is no value defined. They can be used in huge templates, where the authors may not remember all template parameters -- looking at the output, they'll immediately know what was forgotten; if the values are empty, they'll have to go to the template page, view the source and search what was missing.

PmWiki gives you other ways to display nothing if a variable isn't defined: PageTextVariables. In your included template, you can use {*$:Variable}, and in the page with the "include" markup, you define, or not, the PTV (:Variable:Some value:). Alternatively, you can have in your include markup (:include Variable="":) which will hide the {$$Variable} thing in the included template. --Petko November 14, 2009, at 03:18 PM

DaveG: The 'problem' is in comparisons, and trying to determine if the variables are empty. Doing empty comparisons produce results authors would not expect: (:if equal '{$$var}' '':) and similar are not directly possible.

Simon: There is also an issue of consistency, and the principle of "least surprise". I do not consider that different types of variables should display in different ways. To me inconsistency leads to "surprise".
The design appears to provide a means of debugging scripts. In a production wiki I don't want or need this behaviour.
I suggest then that perhaps a config parameter be added that toggles this behaviour on and off, and by default all variables (as shown in the test page) behave in the same manner and do not display their name when empty or not defined.