[Petal] Replace contents of tag only if value is set

Holland, Mark Mark.Holland@commerzbankib.com
Tue, 29 Oct 2002 12:42:07 +0100


> If I understand what you want to do, you shouldn't need a 
> custom handler. 
> Use a condition check like the following:
> 
> 	<tag petal:content="foo" petal:if="bar">Your Message Here</tag>

Ok, but this condition only displays the tag if bar is true. 
I want to be able to display the tag all the time and only replace the
contents if foo is true.
>
> > Can the original contents of the tag be passed to the 
> process routine of > a modifier?
> 
> Yes. See "Writing Your Own Modifiers" in the Expressions document I 
> mentioned above.
>
I can't find anything in the documentation about passing the original
content of a tag to a modifier. Let me try and clarify. I want to be able to
say something like:

# template:
<tag petal:content="mymod: foo">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 $foo = $hash->fetch($args);
	if ($foo eq 'baz') {
		return 'qux';
	} else {
		return $content_of_tag;
	}
  };

Thanks for your help,
Mark

> Good luck,
> William
> 
> -- 
>  Lead Developer
>  Knowmad Services Inc. || Internet Applications & Database Integration
>  http://www.knowmad.com
>  
>