[pmwiki-devel] FmtTemplateVars function
Peter Bowers
pbowers at pobox.com
Tue Feb 10 10:17:50 CST 2009
I agree it seems an unacceptable conflict and probably needs to be changed.
As a workaround I would suggest calling FmtTemplateVars() with only 2
arguments and then FmtPageName() afterwards to handle PVs. (Of course this
gets into the old security problem of globals again... Wasn't there a
suggestion a long time ago to add a 3rd parameter "$secure=false" which when
passed as true would not replace globals or some such solution? But that's
a separate issue...)
-Peter
> -----Original Message-----
> From: pmwiki-devel-bounces at pmichaud.com [mailto:pmwiki-devel-
> bounces at pmichaud.com] On Behalf Of Hans
> Sent: Tuesday, February 10, 2009 4:59 PM
> To: pmwiki-devel at pmichaud.com
> Subject: [pmwiki-devel] FmtTemplateVars function
>
> 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:
> I suggest to use either {$PageVar} (like it is used on normal pages)
> or perhaps {$$$PageVar}.
>
> Making the change in the preg_replace pattern[1] in the function works
> in both cases, in my limited tests.
>
> I think the first is preferable, as we are all used to it, even
> though viewing the template would mean that these vars are evaluated
> and not just appear as placeholders.
>
> ~Hans
>
> [1] current pattern:
> $text = preg_replace("/\\{\\$($pat)\\}/e",
>
> suggested patterns:
> a) $text = preg_replace("/\\{($pat)\\}/e",
> b) $text = preg_replace("/\\{\\$\\$($pat)\\}/e",
>
>
>
> _______________________________________________
> pmwiki-devel mailing list
> pmwiki-devel at pmichaud.com
> http://www.pmichaud.com/mailman/listinfo/pmwiki-devel
More information about the pmwiki-devel
mailing list