Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get WRAPPER functionality from Template::Toolkit in Text::Xslate

I've used Template::Toolkit for my last few Catalyst projects and have a set up that I like using that allows a clean separation of my templates. Now I'm hoping to use Text::Xslate, but I'm having trouble figuring out if I can do my same setup or not. Below is what I have for Template::Toolkit usually.

__PACKAGE__->config({
    ...
    WRAPPER      => 'site/wrapper',
    ...
});

wrapper

[% content WRAPPER site/html + site/layout %]

html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <title>[% template.title or site.title %]</title>
  <style type="text/css">
  </style>
 </head>
 <body>
[% content %]
 </body>
</html>

layout

<div id="header">[% PROCESS site/header %]</div>

<div id="content">
[% content %]
</div>

<div id="footer">[% PROCESS site/footer %]</div>`

And then header and footer have their own content. I like this solution because everything is cleanly separated and I'm not breaking up any div tags around the content by having to put the opening tag in header and the closing in the footer. It looks like with the TTerse syntax there is some wrapper functionality, but I'm not sure if that allows me to recreate what I normally do. I also found this answer that says you can use wrapper in theory, but doesn't really give any examples.

like image 477
srchulo Avatar asked Jul 04 '16 19:07

srchulo


1 Answers

The directive WRAPPER works slightly differently in TTerse then in TT2. This basic syntax works:

[% WRAPPER "include/layout.tt" WITH
   title = "Lipsum" %]

Magna in et vel: feugait erat augue, ut accumsan wisi hendrerit,
eu amet laoreet duis. Duis ex nonummy te lorem blandit et velit
tation erat amet elit dignissim. 

[% END %]

And is include/layout.tt,

# [% title %]

[% content %]

----
Commodo quis magna feugiat ullamcorper, exerci tation ut. 

BLOCK are not supported in TTerse though.

The documentation of TTerse is actually good enough and includes many workable examples: https://metacpan.org/pod/Text::Xslate::Syntax::TTerse#Functions-and-filters

like image 149
gugod Avatar answered Sep 20 '22 12:09

gugod