[pmwiki-devel] FmtTemplateVars function

Patrick R. Michaud pmichaud at pobox.com
Tue Feb 10 10:19:58 CST 2009


On Tue, Feb 10, 2009 at 03:58:33PM +0000, Hans wrote:
> I try to use function FmtTemplateVars in  a new recipe, and finding
> some odd behaviour.
> 
> The function comment reads:
> 
> ##  FmtTemplateVars uses $vars to replace all occurrences of
> #  {$$key} in $text with $vars['key'].
> function FmtTemplateVars($text, $vars, $pagename = NULL) {
> .....
> .....
>   return $text;
> }
> 
> Feeding it a template text with some {$$key} and an array of $vars
> works fine, unless 'key' is a page variable name.
> 
> For instance  {$$Name}  will be replaced by the page name.
> 
> This happens because the function also evaluates page variables,
> which is fine, but expects them in the template with the same syntax
> than the standard replacement variables: {$$key}
> 
> So I think we got a naming conflict, and should really insist on a
> different syntax for page variables in templates:
> [...]

The intent of the extra $ is not to introduce a new class of variables,
but instead to say "perform the substitution as soon as the template
is read" as opposed to "when it is rendered".  Beyond that it's
the same set of available substitutions, and intentionally includes
page variables.

> I suggest to use either {$PageVar} (like it is used on normal pages)
> or perhaps {$$$PageVar}.

No.  The whole reason {$$PageVar} exists is so that {$PageVar}
_won't_ perform a substitution in a template, and thus someone 
viewing/editing the template sees the page variable and not 
its substituted value.

Pm




More information about the pmwiki-devel mailing list