<?php
define("ABS_PATH", $_SERVER['DOCUMENT_ROOT']);
include(ABS_PATH . "/head_nav.php");
include(ABS_PATH . "/middle.php");
?>
          <div class="section">
            <div class="toc-wrapper">
              <span class="toc-title">Contents:</span>
              <ul class="toc">
                  <li class=""><a href="#Template_Toolkit_Language">Template Toolkit Language</a></li>
                  <li class="sub"><a href="#section_Why_doesn_t_a_b_IF_c_work_as_expected_">Why doesn't [% a = b IF c %] work as expected?</a></li>
                  <li class="sub"><a href="#section_If_I_m_using_TT_to_write_out_a_TT_template_is_there_a_good_way_to_escape_and_">If I'm using TT to write out a TT template, is there a good way to escape [% and %]?</a></li>
                  <li class="sub"><a href="#section_How_do_I_iterate_over_a_hash_">How do I iterate over a hash?</a></li>
                  <li class=""><a href="#Plugins">Plugins</a></li>
                  <li class="sub"><a href="#section_How_do_I_get_the_Table_plugin_to_order_data_across_rather_than_down_">How do I get the Table plugin to order data across rather than down?</a></li>
                  <li class="sub"><a href="#section_Accessing_Cookies">Accessing Cookies</a></li>
                  <li class=""><a href="#Extending_the_Template_Toolkit">Extending the Template Toolkit</a></li>
                  <li class="sub"><a href="#section_Can_I_serve_templates_from_a_database_">Can I serve templates from a database?</a></li>
                  <li class="sub"><a href="#section_Can_I_fetch_templates_via_http_">Can I fetch templates via http?</a></li>
                  <li class=""><a href="#Miscellaneous">Miscellaneous</a></li>
                  <li class="sub"><a href="#section_How_can_I_find_out_the_name_of_the_main_template_being_processed_">How can I find out the name of the main template being processed?</a></li>
                  <li class="sub"><a href="#section_How_can_I_find_out_the_name_of_the_current_template_being_processed_">How can I find out the name of the current template being processed?</a></li>
                  <li class="sub"><a href="#section_How_do_I_print_the_modification_time_of_the_template_or_component_">How do I print the modification time of the template or component?</a></li>
                  <li class="sub"><a href="#section_How_can_I_configure_variables_on_a_per_request_basis_">How can I configure variables on a per-request basis?</a></li>
                  <li class="sub"><a href="#section_Why_do_I_get_rubbish_for_my_utf_8_templates_">Why do I get rubbish for my utf-8 templates?</a></li>
                  <li class=""><a href="#Questions_About_This_FAQ">Questions About This FAQ</a></li>
                  <li class="sub"><a href="#section_Why_is_this_FAQ_so_short_">Why is this FAQ so short?</a></li>
                  <li class="sub"><a href="#section_Can_I_help_">Can I help?</a></li>
              </ul>
            </div>
          </div>
          
                <div class="pod">
            <div class="section">
              <div class="head">
                <h1 id="Template_Toolkit_Language">Template Toolkit Language</h1>
                <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
              </div>
              <div class="body">
                <div class="subsection">
                  <div class="head">
                    <h2 id="section_Why_doesn_t_a_b_IF_c_work_as_expected_" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">Why doesn't [% a = b IF c %] work as expected?</h2>
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
                  </div>
                  <div class="body">
                    <p>
                          There's a limitation in the TT2 parser which means that the following
                          code doesn't work as you might expect:
                        </p>
                        <pre><span class="tt">[% a = b IF c %]</span></pre>
                        <p>
                          The parser interprets it as an attempt to set <code>a</code> to the
                          result of <code>b IF c</code>, like this:
                        </p>
                        <pre><span class="tt">[% a = (b IF c) %]</span></pre>
                        <p>
                          If you want to set <code>a = b</code> only if <code>c</code> is true,
                          then do this instead:
                        </p>
                        <pre><span class="tt">[% SET a = b IF c %]</span></pre>
                        <p>
                          The explicit <code>SET</code> keyword gives the parser the clue it needs
                          to do the right thing.
                        </p>
                        <p>
                          NOTE: this will be fixed in TT3
                        </p>
                  </div>
                </div>    <div class="subsection">
                  <div class="head">
                    <h2 id="section_If_I_m_using_TT_to_write_out_a_TT_template_is_there_a_good_way_to_escape_and_" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">If I'm using TT to write out a TT template, is there a good way to escape [% and %]?</h2>
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
                  </div>
                  <div class="body">
                    <p>
                          You can do something like this:
                        </p>
                        <pre><span class="tt">[% stag = "[\%"
   etag = "%\]"
%]</span></pre>
                        <p>
                          and then:
                        </p>
                        <pre><span class="tt">[% stag; 'hello'; etag %]</span></pre>
                        <p>
                          Or you can use the <code>TAGS</code> directive, like so:
                        </p>
                        <pre><span class="tt">[% TAGS [- -] %]</span>
[- INCLUDE foo -]   # is a directive
<span class="tt">[% INCLUDE foo %]</span>   # not a directive</pre>
                  </div>
                </div>    <div class="subsection">
                  <div class="head">
                    <h2 id="section_How_do_I_iterate_over_a_hash_" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">How do I iterate over a hash?</h2>
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
                  </div>
                  <div class="body">
                    <p>
                          This is covered in the <a href="../manual/VMethods.php">Template::Manual::VMethods</a> section of the manual. A list of all
                          the keys that are in the hash can be obtained with the <code>keys</code>
                          virtual method. You can then iterate over that list and by looking up
                          each key in turn get the value.
                        </p>
                        <pre><span class="tt">[% FOREACH key = product.keys %]</span>
   <span class="tt">[% key %]</span> =&gt; <span class="tt">[% product.$key %]</span>
<span class="tt">[% END %]</span></pre>
                  </div>
                </div>
              </div>
            </div>
            <div class="section">
              <div class="head">
                <h1 id="Plugins">Plugins</h1>
                <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
              </div>
              <div class="body">
                <div class="subsection">
                  <div class="head">
                    <h2 id="section_How_do_I_get_the_Table_plugin_to_order_data_across_rather_than_down_" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">How do I get the Table plugin to order data across rather than down?</h2>
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
                  </div>
                  <div class="body">
                    <p>
                          Order the data into rows:
                        </p>
                        <pre>Steve     Karen     Jeff
Brooklyn  Nantucket Fairfax
NY        MA        VA

<span class="tt">[% USE table(data, rows=3) %]</span></pre>
                        <p>
                          Then ask for each column
                        </p>
                        <pre><span class="tt">[% FOREACH column = table.cols %]</span></pre>
                        <p>
                          And then print each item in the column going across the output rows
                        </p>
                        <pre><span class="tt">[% FOREACH item = column %]</span>
    &lt;td&gt;<span class="tt">[% item %]</span>&lt;/td&gt;
<span class="tt">[% END %]</span></pre>
                  </div>
                </div>    <div class="subsection">
                  <div class="head">
                    <h2 id="section_Accessing_Cookies" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">Accessing Cookies</h2>
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
                  </div>
                  <div class="body">
                    <p>
                          Jeff Boes &lt;jboes@nexcerpt.com&gt; asks:
                        </p>
                        <pre>Does anyone have a quick-n-dirty approach to accessing 
cookies from templates?</pre>
                        <p>
                          Jonas Liljegren answers:
                        </p>
                        <pre><span class="tt">[% USE CGI %]</span>

&lt;p&gt;The value is <span class="tt">[% CGI.cookie('cookie_name') | html %]</span></pre>
                  </div>
                </div>
              </div>
            </div>
            <div class="section">
              <div class="head">
                <h1 id="Extending_the_Template_Toolkit">Extending the Template Toolkit</h1>
                <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
              </div>
              <div class="body">
                <div class="subsection">
                  <div class="head">
                    <h2 id="section_Can_I_serve_templates_from_a_database_" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">Can I serve templates from a database?</h2>
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
                  </div>
                  <div class="body">
                    <p>
                          Short answer: yes, Chris Nandor has done this for Slash. You need to
                          subclass <a href="../modules/Template/Provider.php">Template::Provider</a>. See the mailing list archives for further
                          info.
                        </p>
                  </div>
                </div>    <div class="subsection">
                  <div class="head">
                    <h2 id="section_Can_I_fetch_templates_via_http_" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">Can I fetch templates via http?</h2>
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
                  </div>
                  <div class="body">
                    <p>
                          To do the job properly, you should subclass <a href="../modules/Template/Provider.php">Template::Provider</a> to
                          <code>Template::Provider::HTTP</code> and use a <code>PREFIX_MAP</code>
                          option to bind the <code>http</code> template prefix to that particular
                          provider (you may want to go digging around in the <i>Changes</i> file
                          around version 2.01 for more info on <code>PREFIX_MAP</code> - it may not
                          be properly documented anywhere else...yet!). e.g.
                        </p>
                        <pre>use Template::Provider::HTTP;

my $file = Template::Provider( INCLUDE_PATH =&gt; [...] );
my $http = Template::Provider::HTTP-&gt;new(...);
my $tt2  = Template-&gt;new({
    LOAD_TEMPLATES =&gt; [ $file, $http ],
    PREFIX_MAP =&gt; {
        file    =&gt; '0',     # file:foo.php
        http    =&gt; '1',     # http:foo.php
        default =&gt; '0',     # foo.php =&gt; file:foo.php
    }
});</pre>
                        <p>
                          Now a template specified as:
                        </p>
                        <pre><span class="tt">[% INCLUDE foo %]</span></pre>
                        <p>
                          will be served by the 'file' provider (the default). Otherwise you can
                          explicitly add a prefix:
                        </p>
                        <pre><span class="tt">[% INCLUDE file:foo.php %]</span>
<span class="tt">[% INCLUDE http:foo.php %]</span>
<span class="tt">[% INCLUDE http://www.xyz.com/tt2/header.tt2 %]</span></pre>
                        <p>
                          This same principal can be used to create a DBI template provider. e.g.
                        </p>
                        <pre><span class="tt">[% INCLUDE dbi:foo.php %]</span></pre>
                        <p>
                          Alas, we don't yet have a DBI provider as part of the Template Toolkit.
                          There has been some talk on the mailing list about efforts to develop DBI
                          and/or HTTP providers but as yet no-one has stepped forward to take up
                          the challenge...
                        </p>
                        <p>
                          In the mean time, Craig Barrat's post from the mailing list has some
                          useful pointers on how to achieve this using existing modules. See <a
                          href="http://tt2.org/pipermail/templates/2001-May/000954.php">http://tt2.org/pipermail/templates/2001-May/000954.php</a>
                        </p>
                  </div>
                </div>
              </div>
            </div>
            <div class="section">
              <div class="head">
                <h1 id="Miscellaneous">Miscellaneous</h1>
                <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
              </div>
              <div class="body">
                <div class="subsection">
                  <div class="head">
                    <h2 id="section_How_can_I_find_out_the_name_of_the_main_template_being_processed_" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">How can I find out the name of the main template being processed?</h2>
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
                  </div>
                  <div class="body">
                    <p>
                          The <code>template</code> variable contains a reference to the
                          Template::Document object for the main template you're processing (i.e.
                          the one provided as the first argument to the Template process() method).
                          The <code>name</code> method returns its name.
                        </p>
                        <pre><span class="tt">[% template.name %]</span>     # e.g. index.php</pre>
                  </div>
                </div>    <div class="subsection">
                  <div class="head">
                    <h2 id="section_How_can_I_find_out_the_name_of_the_current_template_being_processed_" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">How can I find out the name of the current template being processed?</h2>
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
                  </div>
                  <div class="body">
                    <p>
                          The <code>template</code> variable always references the <i>main</i>
                          template being processed. So even if you call [% INCLUDE header %], and
                          that calls [% INCLUDE menu %], the <code>template</code> variable will be
                          unchanged.
                        </p>
                        <p>
                          index.php:
                        </p>
                        <pre><span class="tt">[% template.name  %]</span>     # index.php
<span class="tt">[% INCLUDE header %]</span></pre>
                        <p>
                          header:
                        </p>
                        <pre><span class="tt">[% template.name  %]</span>     # index.php
<span class="tt">[% INCLUDE menu   %]</span></pre>
                        <p>
                          menu:
                        </p>
                        <pre><span class="tt">[% template.name  %]</span>     # index.php</pre>
                        <p>
                          In constrast, the <code>component</code> variable always references the
                          <i>current</i> template being processed.
                        </p>
                        <p>
                          index.php
                        </p>
                        <pre><span class="tt">[% component.name %]</span>     # index.php
<span class="tt">[% INCLUDE header %]</span></pre>
                        <p>
                          header:
                        </p>
                        <pre><span class="tt">[% component.name %]</span>     # header
<span class="tt">[% INCLUDE menu   %]</span></pre>
                        <p>
                          menu:
                        </p>
                        <pre><span class="tt">[% component.name  %]</span>     # menu</pre>
                  </div>
                </div>    <div class="subsection">
                  <div class="head">
                    <h2 id="section_How_do_I_print_the_modification_time_of_the_template_or_component_" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">How do I print the modification time of the template or component?</h2>
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
                  </div>
                  <div class="body">
                    <p>
                          The <code>template</code> and <code>component</code> variables reference
                          the main template and the current template being processed (see previous
                          questions). The <code>modtime</code> method returns the modification time
                          of the corresponding template file as a number of seconds since the Unix
                          epoch (00:00:00 GMT 1st January 1970).
                        </p>
                        <p>
                          This number doesn't mean much to anyone (except perhaps serious Unix
                          geeks) so you'll probably want to use the Date plugin to format it for
                          human consumption.
                        </p>
                        <pre><span class="tt">[% USE Date %]</span>
<span class="tt">[% template.name %]</span> last modified <span class="tt">[% Date.format(template.modtime) %]</span></pre>
                  </div>
                </div>    <div class="subsection">
                  <div class="head">
                    <h2 id="section_How_can_I_configure_variables_on_a_per_request_basis_" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">How can I configure variables on a per-request basis?</h2>
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
                  </div>
                  <div class="body">
                    <p>
                          One easy way to achieve this is to define a single
                          <code>PRE_PROCESS</code> template which loads in other configuration
                          files based on variables defined or other conditions.
                        </p>
                        <p>
                          For example, my setup usually looks something like this:
                        </p>
                        <pre>PRE_PROCESS =&gt; 'config/main'</pre>
                        <p>
                          config/main:
                        </p>
                        <pre><span class="tt">[%  DEFAULT  style   = 'text'
             section =  template.section or 'home';

    PROCESS  config/site
          +  config/urls
          +  config/macros
          + "config/style/$style"
          + "config/section/$section"
          + ...
%]</span></pre>
                        <p>
                          This allows me to set a single 'style' variable to control which config
                          file gets pre-processed to set my various style options (colours, img
                          paths, etc). For example:
                        </p>
                        <p>
                          config/style/basic:
                        </p>
                        <pre><span class="tt">[%  style = {
        name = style    # save existing 'style' var as 'style.name'

        # define various other style variables....
        col = {
            back =&gt; '#ffffff'
            text =&gt; '#000000'
                # ...etc...
        }

        logo = {
                # ...etc...
        }

        # ...etc...
    }
%]</span></pre>
                        <p>
                          Each source template can declare which section it's in via a META
                          directive:
                        </p>
                        <pre><span class="tt">[% META
 title   = 'General Information'
 section = 'info'
%]</span>
...</pre>
                        <p>
                          This controls which section configuration file gets loaded to set various
                          other variables for defining the section title, menu, etc.
                        </p>
                        <p>
                          config/section/info:
                        </p>
                        <pre><span class="tt">[%  section = {
        name   = section  # save 'section' var as 'section.name'
        title  = 'Information'
        menu   = [ ... ]
        # ...etc...
    }
%]</span></pre>
                        <p>
                          This illustrates the basic principal but you can extend it to perform
                          pretty much any kind of per-document initialisation that you require.
                        </p>
                  </div>
                </div>    <div class="subsection">
                  <div class="head">
                    <h2 id="section_Why_do_I_get_rubbish_for_my_utf_8_templates_" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">Why do I get rubbish for my utf-8 templates?</h2>
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
                  </div>
                  <div class="body">
                    <p>
                          First of all, make sure that your template files define a Byte Order Mark
                          <a
                          href="http://en.wikipedia.org/wiki/Byte_Order_Mark">http://en.wikipedia.org/wiki/Byte_Order_Mark</a>
                        </p>
                        <p>
                          If you for some reason don't want to add BOM to your templates, you can
                          force Template to use a particular encoding (e.g. <code>utf8</code>) for
                          your templates with the <code>ENCODING</code> option.
                        </p>
                        <pre>my $template = Template-&gt;new({ 
    ENCODING =&gt; 'utf8' 
});</pre>
                  </div>
                </div>
              </div>
            </div>
            <div class="section">
              <div class="head">
                <h1 id="Questions_About_This_FAQ">Questions About This FAQ</h1>
                <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
              </div>
              <div class="body">
                <div class="subsection">
                  <div class="head">
                    <h2 id="section_Why_is_this_FAQ_so_short_" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">Why is this FAQ so short?</h2>
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
                  </div>
                  <div class="body">
                    <p>
                          Because we don't have anyone maintaining it.
                        </p>
                  </div>
                </div>    <div class="subsection">
                  <div class="head">
                    <h2 id="section_Can_I_help_" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">Can I help?</h2>
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
                  </div>
                  <div class="body">
                    <p>
                          Yes please :-)
                        </p>
                  </div>
                </div>
              </div>
            </div>
            
            </div>
<?php include(ABS_PATH . "/footer.php"); ?>
