about Wrapper

37 views
Skip to first unread message

ktat

unread,
Aug 6, 2011, 1:56:13 AM8/6/11
to Xslate
Hi

I'm using TTerse and try to use WRAPPER.
I wrote the following code like the last example in
http://search.cpan.org/~gfuji/Text-Xslate-1.4001/lib/Text/Xslate/Syntax/TTerse.pm#Template_inclusion

$tx = Text::Xslate->new(
'syntax' => 'TTerse',
'path' => [{
wrap_begin => '[% WRAPPER "include/
layout.tt" %]',
wrap_end => '[% END %]',
content => 'Xslate',
},
'/path/to/template/',
],
'header' => ['wrap_begin'],
'footer' => ['wrap_end'],
);

Tempalte example:

include/layout.tt
---------------------------
<htmlt><head><title>[% title %]</title></head><body>[% content %]</
body></html>
---------------------------

index.tt
---------------------------
[% title = "HELLO" %] <- this definition is no use
Hello, world
---------------------------

Can I define variables in wrapper template(inclue/layout.tt) from the
template(index.tt) to be wrapped?
define variables in code or use [% WRAPPER 'include/lyaout.tt'
WITH ... %] in index.tt ?

Thanks.

Fumiaki Yoshimatsu

unread,
Aug 9, 2011, 9:28:47 PM8/9/11
to Xslate
Hi ktat,

So, having WRAPPER directive and WITH with variables works fine for
us, but I might not have got your point. Do you not want to have
something like below in your template? Was that what you meant?

$ cat /tmp/tt/index.tx
[% WRAPPER "include/t.tt" WITH title = "HELLO" %]
Hello, world
[% END %]

Fumiaki

On Aug 6, 2:56 pm, ktat <ktat...@gmail.com> wrote:
> Hi
>
> I'm using TTerse and try to use WRAPPER.
> I wrote the following code like the last example inhttp://search.cpan.org/~gfuji/Text-Xslate-1.4001/lib/Text/Xslate/Synt...

ktat

unread,
Aug 10, 2011, 12:49:47 AM8/10/11
to xsl...@googlegroups.com
Hi, Fumiaki.

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

Daisuke Maki

unread,
Aug 10, 2011, 12:53:41 AM8/10/11
to xsl...@googlegroups.com
You probably should include a minimal example of what's not working.

--d

2011/8/10 ktat <kta...@gmail.com>:

ktat

unread,
Aug 10, 2011, 1:40:55 AM8/10/11
to xsl...@googlegroups.com
Sorry, can embed variables to footer.

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---

Reply all
Reply to author
Forward
0 new messages