[pmwiki-users] edit templates: auto update dates?

Stirling Westrup sti at pooq.com
Thu Apr 10 18:13:17 CDT 2008


Henrik wrote:
> Regarding http://www.pmwiki.org/wiki/Cookbook/EditTemplates
> 
> Is it possible to automatically update dates, to that the imported text 
> contains the current date (as text, not as a variable).
> 
> So for example if creating a page today, I would like the title, as 
> imported from the template, to have in the edit textbox
> 
> !!!!Farmers' Market news for April 10, 2008
> 
> Where the date is written in as clear text from the template.
> 

When I started using edit templates, I found the same need for having
things evaluated at edit time. I came up with this simple recipe. It
assumes that the $EditTemplatesFmt is set like this:

$EditTemplatesFmt = '{$SiteGroup}.{$Group}-Template';

But it would be fairly easy to fix it.

#
# Edit template vars and expressions.
#
# Use <<$Foo>> instead of {$Foo} and
# <<(func ...)>> instead of {(func ...)}
#
# to have them evaluated before edit.
#
$pn=MakePageName($pagename,$pagename);
if( !preg_match("/^$SiteGroup\..*-Template$/",$pn) )
  $ROEPatterns = array
    ( '/<<(\\*|!?[-\\w.\\/\\x80-\\xff]*)(\\$:?\\w+)>>/e'
      => "PRR(PVSE(PageVar(\$pagename, '$2', '$1')))"
    , '/<<(\\(\\w+\\b.*?\\))>>/e'
      => "MarkupExpression(\$pagename, PSS('$1'))"
    );


Once you have this in your local/config.php, all you need to do is write
a template with contents like this:

!!!!Farmers' Market news for <<(ftime "%B %d, %Y" )>>





More information about the pmwiki-users mailing list