[Catalyst-commits] r8605 - Catalyst-Manual/5.70/branches/no_ttsite/lib/Catalyst/Manual/Tutorial

dhoss at dev.catalyst.perl.org dhoss at dev.catalyst.perl.org
Mon Nov 17 00:26:34 GMT 2008


Author: dhoss
Date: 2008-11-17 00:26:33 +0000 (Mon, 17 Nov 2008)
New Revision: 8605

Modified:
   Catalyst-Manual/5.70/branches/no_ttsite/lib/Catalyst/Manual/Tutorial/MoreCatalystBasics.pod
Log:
rewrote to use TT instead of TTSite.

Modified: Catalyst-Manual/5.70/branches/no_ttsite/lib/Catalyst/Manual/Tutorial/MoreCatalystBasics.pod
===================================================================
--- Catalyst-Manual/5.70/branches/no_ttsite/lib/Catalyst/Manual/Tutorial/MoreCatalystBasics.pod	2008-11-16 22:36:27 UTC (rev 8604)
+++ Catalyst-Manual/5.70/branches/no_ttsite/lib/Catalyst/Manual/Tutorial/MoreCatalystBasics.pod	2008-11-17 00:26:33 UTC (rev 8605)
@@ -342,25 +342,23 @@
 tricky to customize.  Additionally TT contains constructs that you
 need to learn yourself if you're going to be a serious user of TT.
 Our experience suggests that you're better off learning these from
-scratch.  We use TTSite here precisely because it is useful for
-bootstrap/prototype purposes.
+scratch.  We use plain TT since it is good practice and helps you follow
+proper Catalyst conventions from the start.
 
-Enter the following command to enable the C<TTSite> style of view
+Enter the following command to enable the C<TT> style of view
 rendering for this tutorial:
 
-    $ script/myapp_create.pl view TT TTSite
-     exists "/home/me/MyApp/script/../lib/MyApp/View"
-     exists "/home/me/MyApp/script/../t"
-    created "/home/me/MyApp/script/../lib/MyApp/View/TT.pm"
-    created "/home/me/MyApp/script/../root/lib"
-    ...
-    created "/home/me/MyApp/script/../root/src/ttsite.css"
+    $ script/myapp_create.pl view TT TT
+     exists "/home/devin/web-development/MyApp/script/../lib/MyApp/View"
+     exists "/home/devin/web-development/MyApp/script/../t"
+     created "/home/devin/web-development/MyApp/script/../lib/MyApp/View/TT.pm"
+     created "/home/devin/web-development/MyApp/script/../t/view_TT.t"
 
-This puts a number of files in the C<root/lib> and C<root/src>
-directories that can be used to customize the look and feel of your
-application.  Also take a look at C<lib/MyApp/View/TT.pm> for config
-values set by the C<TTSite> helper.
 
+This simply creates a view called TT. It is now up to you to decide how you
+want to structure your view layout.  The following is a fairly sane method
+of structuring, but you are more than welcome to change it to your taste.
+
 B<TIP>: When troubleshooting TT it can be helpful to enable variable
 C<DEBUG> options.  You can do this in a Catalyst environment by adding
 a C<DEBUG> line to the C<__PACKAGE__->config> declaration in 
@@ -391,21 +389,119 @@
 
 =head2 Globally Customize Every View
 
-When using TTSite, files in the subdirectories of C<root/lib> can be
-used to make changes that will appear in every view.  For example, to
-display optional status and error messages in every view, edit
-C<root/lib/site/layout>, updating it to match the following (the two HTML
-C<span> elements are new):
+When using TT, you can (and should!) create a wrapper that will
+literally wrap content around each of your templates.  This is certainly
+useful as you have one main source for changing things that will appear
+across your entire site/application instead of having to edit many individual files.  
 
-    <div id="header">[% PROCESS site/header %]</div>
+In order to create a wrapper, you must first edit your TT view and
+tell it where to look for your wrapper. Your TT view is located in lib/MyApp/View/TT.pm.
+
+In TT.pm, this is what you should see (or something very similar):
+
+
+    __PACKAGE__->config(
+        TEMPLATE_EXTENSION => '.tt2'
+    );
+
+I<(Note that I've changed> C<TEMPLATE_EXTENSION> I<to> C<'.tt2'> I<out of preference. This is not necessary.>
+
+Append the following (Make sure to add a comma after '.tt2' outside the single quote):
+
+    TEMPLATE_EXTENSION => '.tt2',
     
+    ## This tells Catalyst where to look
+    ## for your TT files
+    INCLUDE_PATH =>
+        [ 
+            MyApp->path_to( 'root' ) 
+        ],
+
+    CATALYST_VAR       => 'c',
+    TIMER              => 0,
+
+    ## This is your wrapper template
+    ## it will be located it the 'root/' directory
+    ## of your application
+    WRAPPER => 'wrapper',
+
+
+
+Voila, your View is configured.  Next you need to set up your wrapper
+template.  Basically, you'll want to take the layout of your site and put
+it into this file.  In your <title> tag, you'll most likely want to put something like 
+C<[% template.title or "My Catalyst App!" %]> so you can set your title (via C<META> or
+some such) in your templates later on.  
+
+Here is an example wrapper:
+
+    <?xml version="1.0" encoding="UTF-8"?>
+    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+    <head>
+    <title>[% template.title or "My Catalyst App!" %]</title>
+    <link rel="stylesheet" href="[% c.uri_for('/static/styles/main.css') %]" />
+
+    </head>
+    <body>
+
+    <body>
+    <div id="outer">
+    <div id="header" align="center">
+    <!-- your logo could go here -->
+    <img src="[% c.uri_for('/static/images/logo.png') %]" />
+    </div>
+
+    <div id="bar">
+
+    <div id="vdividermenu">
+    <!-- just a divider -->
+    </div>
+    </div>
+
+    <div id="bodyblock" align="right">
+    <div id="l-col">
+    <div id="menu">
+    <ul><h2>Pictures and Products</h2>
+    <ul>
+    
+        <li><a href="[% c.uri_for('/') %]">Home</a></li>
+        <li><a href="[% c.uri_for('/contact') %]" title="Contact Us">Contact Us</a></li>
+        <li><a href="[% c.uri_for('/about') %]" title="About Us">About</a></li>
+
+    </ul>
+
+    </div>
+    </div>
+
     <div id="content">
+    <p>
+        [%# This is where TT will stick all of your template's contents. %]
+        [% content %]
+
+    </p>
+
+    </div>
+    </div>
+    <div id="footer" align="center">Copyright (c) your name goes here</div>
+
+    </div>
+
+    </body>
+    </html>
+
+
+
+A few things that are useful to add to your wrapper are C<div>s to display error/status messages.
+Put the following code below C<div id="content">> and above C<<p>>:
+
+    
+    
+    
     <span class="message">[% status_msg %]</span>
     <span class="error">[% error_msg %]</span>
-    [% content %]
-    </div>
     
-    <div id="footer">[% PROCESS site/footer %]</div>
+    
 
 If we set either message in the Catalyst stash (e.g.,
 C<$c-E<gt>stash-E<gt>{status_msg} = 'Request was successful!'>) it will
@@ -1051,24 +1147,7 @@
         #$c->stash->{template} = 'books/list.tt2';
     }
 
-C<Catalyst::View::TT> defaults to looking for a template with no 
-extension.  In our case, we need to override this to look for an 
-extension of C<.tt2>.  Open C<lib/MyApp/View/TT.pm> and add the 
-C<TEMPLATE_EXTENSION> definition as follows:
 
-    __PACKAGE__->config({
-        CATALYST_VAR => 'Catalyst',
-        INCLUDE_PATH => [
-            MyApp->path_to( 'root', 'src' ),
-            MyApp->path_to( 'root', 'lib' )
-        ],
-        PRE_PROCESS  => 'config/main',
-        WRAPPER      => 'site/wrapper',
-        ERROR        => 'error.tt2',
-        TIMER        => 0,
-        TEMPLATE_EXTENSION => '.tt2',
-    });
-
 You should now be able to restart the development server as per the 
 previous section and access the L<http://localhost:3000/books/list>
 as before.




More information about the Catalyst-commits mailing list