I change subject. this is the problem about header & footer option.
I know, WRAPPER and WITH works fine.
But, I want not to write [% WRAPPER '...' %] ... [% END %] to all template file.
So, I use the last example of TTerse document about "Template Inclusion".
(http://search.cpan.org/~gfuji/Text-Xslate-1.4001/lib/Text/Xslate/Syntax/TTerse.pm#Template_inclusion)
In this example '[% WRAPPER ... %] in header option and '[% END %]' in footer option.
Using this way, I remove [% WRAPPER '...' %] ... [% END %] from all template file,
however I cannot define variables for WRAPPER(include/layout.tt) in template file.
In my use case using wrapper,
* change title
* change css files
* change js files
* set bread crumbs
* etc.
They are all HTML coders' matter. But, header & footer option is written in code and
only programmer can embed variables to header/footer.
If we have the way to define variables for header/footer from template file, this problem is solved.
If we have no way to do this, in my opinion, I think header and footer option is practically no use.
> --
> You received this message because you are subscribed to the Google
> Groups "Xslate" group.
> To post to this group, send email to xsl...@googlegroups.com
> To unsubscribe from this group, send email to
> xslate+un...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/xslate
>
--
Kato Atsushi (Ktat)
mailto:kta...@gmail.com
--d
2011/8/10 ktat <kta...@gmail.com>:
minimal code is the following.
example 1
######################################################################################################
use Text::Xslate;
my $tx = Text::Xslate->new({path => {'header' => '[% var_h %]', footer => '[% var_f %]'},
header => ['header'],
footer => ['footer'],
syntax => 'TTerse',
});
print $tx->render_string('[% var_h = 1 %]---[% var %]---[% var_f = 2 %]', {var => "hello"});
######################################################################################################
OUTPUT: ---hello---2
example 2 (WRAPPER)
######################################################################################################
use Text::Xslate;
my $tx = Text::Xslate->new({path => ['./',{'header' => '[% WRAPPER "layout.tt" %]',footer => '[% END %]'}],
header => ['header'],
footer => ['footer'],
syntax => 'TTerse',
});
print $tx->render_string('[% var_h = 1 %][% var %][% var_f = 2 %]', {var => "hello"});
######################################################################################################
layout.tt
######################################################################################################
[% var_h %]---[% content %]---[% var_f %]
######################################################################################################
OUTPUT: ---hello---