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

Dominique Faure dominique.faure at gmail.com
Fri Apr 11 10:07:39 CDT 2008


On Fri, Apr 11, 2008 at 1:13 AM, Stirling Westrup <sti at pooq.com> wrote:
> 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" )>>
>
>
>
> _______________________________________________
> pmwiki-users mailing list
> pmwiki-users at pmichaud.com
> http://www.pmichaud.com/mailman/listinfo/pmwiki-users
>

The following code snippet would provide the same kind of feature
wherever you decided to put your template file(s). You just have to
use {$$var} and {$(func ...)} instead of {$var} and {(func ...)} to
have them evaluated when creating a new page:

  $EditFunctions[array_search('EditTemplate', $EditFunctions)] =
'EditFilledTemplate';

  function EditFilledTemplate($pagename, &$page, &$new) {
    if(@$new['text'] > '') return;
    EditTemplate($pagename, $page, $new);
    $new['text'] = preg_replace("/\\{\\$(\\(\\w+\\b.*?\\))\\}/e",
                                "MarkupExpression(\$pagename, PSS('$1'))",
                                FmtTemplateVars($new['text'], array(),
$pagename));
  }

-- 
Dominique



More information about the pmwiki-users mailing list