[pmwiki-users] new page attribute
Patrick R. Michaud
pmichaud at pobox.com
Mon Sep 25 21:18:31 CDT 2006
On Mon, Sep 25, 2006 at 10:02:15PM -0400, Henrik Bechmann wrote:
> Not good...
> >However, if we're just displaying the summary field, it's far more
> >efficient to simply write
> >
> > {$:Summary}
> >
> But if I don't get to test it, I don't get the chance to substitute
> something else (eg description or title) if the summary is absent...
One could write a custom page variable to handle the substitution
exactly as you wish:
$FmtPV['$Summary'] = 'Summary($pn)';
function Summary($pagename) {
$v = PageVar($pagename, '$:Summary');
if (!$v) $v = PageVar($pagename, '$Description');
if (!$v) $v = PageVar($pagename, '$Title');
return $v;
}
This causes {$Summary} to return {$:Summary} if it's defined,
otherwise it returns the page description, otherwise it returns
the title.
We can also add a custom 'summary' condition
$Conditions['summary'] = '(boolean)PageVar($pagename, "$:Summary")'
and then use (:if summary:) to test for the summary definition.
> >>$FmtPV['$Summary'] = '$page["summary"]';
> >>
> >Well, you can do that, but if you're setting it up as a separate
> >input field, it's not really a page text variable or a "property"
> >in the sense that we've been using that word here. ("Properties"
> >are values defined in the markup.) It's just another attribute of
> >the page that is being managed as a separate field.
> >
> It seems to me, in light of what you've said, that this would be the
> simplest option for my requirements. Presuming there is a legitimate way
> of adding such an attribute to a page, and managing it.
Adding such an attribute isn't too bad; you'll want a custom
entry in $EditFunctions that manages the attribute.
Pm
More information about the pmwiki-users
mailing list