[WM] Re: WebMake: define_empty_tag changed behaviour?
Justin Mason
jm.jmason.org
Fri Oct 12 22:45:10 IST 2001
(cc'ed to list, since the techniques used are quite interesting.)
Norbert Gawor said:
> after debugging one day I again dare to bother you.
no bother involved, happy to help!
> After all, I have found a solution to the following problem
> but still would like to understand what's going on here:
> I want to define a "HTML" tag to be used like
>
> <pref handle=NGA />
> Here is my code:
>
> <{perl
> define_empty_tag ("pref", \&pref_hdl, qw(handle));
>
> sub pref_hdl() {
> my ($tagname, $attrs, $text, $perlcode) = @_;
> my $h = $attrs->{"handle"};
>
> my $co = get_content_object($h);
> # this seems to work because I could also
> # do a $co->get_title()
> # and also $co->as_string()
>
> my $persadr = $co->get_metadata("adresse");
> # But $persadr is always undefined :-(
>
> my $s2 = get_content("$h.adresse");
> # This is my workaround (even if the docu says:
> # get_content is equivalent to ${name.meta}, *not*
> $[name.meta] )
Since perl code and user tags are evaluated immediately on the first pass,
the metadata will probably not be defined yet, at that point.
I would suggest that instead of calling get_metadata() in the code, you
just insert the text "$[name.adresse]" (where name is the content item's
name) and let WebMake expand it later (when the metadatum has been set).
Alternatively, if you need to do some manipulation on the metadatum for
some reason, another (more complex) technique to delay evaluation of code
until metadata has been defined, is as follows: simply define a content
item which runs perl code, then refer to that content item using a
$[deferred] reference.
Since the $[..] style of reference is actually just a normal content
reference, delayed until after all metadata has been defined, this will
work (at least it should work ;)
e.g.:
...perl code...
$output .= "$[modify_adresse: name=\"foo\"]";
...perl code...
(Note the use of a 'parameterized reference', a new feature added in the
last release!)
Then define modify_adresse as:
<template name=modify_adresse>
<{perl
my $name = get_content ("name");
my $adr = get_content ($name.".adresse");
... modify $adr in some way...
$adr;
}>
</template>
(BTW, I will add a warning to the POD documentation about get_metadata().
It sohuld be noted that that method should only be called itself from a
deferred ref.)
HTH!
--j.
More information about the Webmake-talk
mailing list