[Petal] Replace contents of tag only if value is set
William McKee
william@knowmad.com
Tue, 29 Oct 2002 08:42:48 -0500
On 29 Oct 2002 at 14:04, Holland, Mark wrote:
> Admittedly this would work, but apart from not tending to very tidy
> templates, it still doesn't address my problem that I need to pass the
> content's of a tag to a modifier.
Hmmm, I think Jean-Michel will have to answer that one. In the meantime,
why don't you pass the value to the modifier as follows:
# template:
<tag petal:content="mymod: foo Bar">Bar</tag>
# modifier:
$Petal::Hash::MODIFIERS->{'mymod:'} = sub {
my $hash = shift;
my $args = shift; # should be 'foo'
#my $content_of_tag = shift; # should be set to 'Bar'
my ($arg1, $arg2) = split /\s/, $args;
my $a1 = $hash->fetch($arg1);
my $a2 = $hash->fetch($arg2); # set to 'Bar'
my $foo = $hash->fetch($args);
if ($foo eq 'baz') {
return 'qux';
} else {
#return $content_of_tag;
return $a2;
}
};
----------------------
Admittedly, you have to the enter the Bar twice if you insist on having it
displayed in the tag. The more I look at this problem though, the more I
wonder what you're driving for. Are you trying to get clean templates for
a GUI editor so you don't get both outputs showing up? What's wrong with
the method that Chris presented?
Hope this helps,
William
--
Lead Developer
Knowmad Services Inc. || Internet Applications & Database Integration
http://www.knowmad.com