Skip to content
Browse files

Example of processing a wrapper and choosing the template

  • Loading branch information...
1 parent 286e768 commit aec18dada7c69ae1961f015b337ac40ed86b7296 @ranguard committed
View
18 tt_process_wrapper/app.psgi
@@ -0,0 +1,18 @@
+use strict;
+use Plack::Builder;
+
+use Plack::Middleware::TemplateToolkit;
+
+
+my $app = Plack::Middleware::TemplateToolkit->new(
+ root => 'root', # required
+ PROCESS => 'wrappers/master.html',
+)->to_app;
+
+
+return builder {
+enable 'Debug';
+enable 'Debug::TemplateToolkit';
+ $app;
+}
+
View
13 tt_process_wrapper/root/1.html
@@ -0,0 +1,13 @@
+[%
+ page = {
+ wrapper => 1,
+ title => 'Page 1 title',
+ };
+
+%]
+
+[% BLOCK head_js %]
+ Test
+[% END %]
+
+Content for page 1
View
10 tt_process_wrapper/root/2.html
@@ -0,0 +1,10 @@
+[%
+ page = {
+ wrapper => 2,
+ title => 'Page 2 title'
+ };
+%]
+[% BLOCK head_js %]
+ Put this in HERE;
+[% END %]
+Content for page 2
View
11 tt_process_wrapper/root/wrappers/1
@@ -0,0 +1,11 @@
+<body>
+<h2>Template 1: [% page.title %]</h2>
+
+<p>
+[% content %]
+</p>
+
+[% PROCESS head_js %]
+
+<h2>End template 1</h2>
+</body>
View
12 tt_process_wrapper/root/wrappers/2
@@ -0,0 +1,12 @@
+<body>
+<h2>Template 2: [% page.title %]</h2>
+
+<p>
+[% content %]
+</p>
+
+<h2>End template 2</h2>
+
+[% PROCESS head_js %]
+
+</body>
View
15 tt_process_wrapper/root/wrappers/master.html
@@ -0,0 +1,15 @@
+<!doctype html>
+<html lang="en" class="no-js">
+[%
+ # Get the content of the page
+ content = PROCESS $template;
+
+ # Now choose and process the wrapper
+ IF page.wrapper;
+ wrapper = "wrappers/" _ page.wrapper;
+ PROCESS $wrapper;
+ ELSE;
+ content;
+ END;
+%]
+</html>
View
15 tt_process_wrapper/root/wrappers/master.tt
@@ -0,0 +1,15 @@
+<!doctype html>
+<html lang="en" class="no-js">
+[%
+ # Get the content of the page
+ content = PROCESS $template;
+
+ # Now choose and process the wrapper
+ IF page.wrapper;
+ wrapper = "wrappers/" _ page.wrapper _ '.tt';
+ PROCESS $wrapper;
+ ELSE;
+ content;
+ END;
+%]
+</html>

0 comments on commit aec18da

Please sign in to comment.
Something went wrong with that request. Please try again.