Well, I don't know any way how to define a custom directive. But, there's a way
how to define custom sub, so you are allowed to do something like:
use strict;
use warnings;
use Template;
my $template = Template->new();
sub delete {
delete($template->context()->stash()->{$_[0]});
return;
}
$template->process( \*DATA, { delete => \&delete } ) || print
$template->error();
__DATA__
[% SET foo = 123 -%]
[% IF foo.defined %] foo is now defined [% ELSE %] foo is now undefined [% END
%]
[%- delete('foo') # foo must be in apostrophes %]
[% IF foo.defined %] foo is now defined [% ELSE %] foo is now undefined [% END
%]
It's horrible, but it works ;)
S pozdravem /Kind regards
Petr Danihlík
Oddělení elektroniky/Electronic Department
ZF Engineering Plzeň
301 00 Plzeň, Česká republika/Czech Republic
Telefon/Phone +420 373 736-393, Telefax/Fax +420 377 831-312
[email protected]
-----Original Message-----
From: Felipe Gasper (cPanel) [mailto:[email protected]]
Sent: Friday, December 11, 2009 4:54 PM
To: Danihlik Petr PLZ ELD
Subject: Re: [Templates] Can I "DELETE some_var"?
Quoth [email protected] on 12/11/2009 8:49 AM...
> At least, following should work:
>
> [% SET foo = 1 %]
> [% IF foo.defined %] defined1 [% END %]
> [% PERL %]
> delete($stash->{foo});
> [% END %]
> [% IF foo.defined %] defined2 [% END %]
>
> Does it help?
Not really...we have hard-set the TT processor not to allow inline perl. :(
-F
>
> Best regards
> Petr Danihlík
>
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of Felipe Gasper
> (cPanel)
> Sent: Friday, December 11, 2009 3:44 PM
> To: [email protected]
> Subject: [Templates] Can I "DELETE some_var"?
>
> Is there a way to delete a variable from the stash in TT2?
>
> If not, does something let me define a custom directive to do this?
>
> -F
>
--
Felipe Gasper
Linux/BSD development
cPanel of Texas, LLC
3701 Kirby Dr., suite 428
Houston, TX 77098
office 713-529-0800 x4096
cell 832-633-8092
fax 713-559-3206
_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates