Hi TrixieTang

Here are a couple of things that might help – there are two ways to “attempt to use it” both of which ought to be installed as part of Template::Toolkit.

Generating Output

tpage

You need to specify the extension of the include files (and location of said include files if they're not in the current working directory). So your example.tt file will look like this:

[% INCLUDE header.tt title = 'This is an HTML example'; pages = [ { url = 'http://foo.org' title = 'The Foo Organisation' } { url = 'http://bar.org' title = 'The Bar Organisation' } ] %] <h1>Some Interesting Links</h1> <ul> [% FOREACH page IN pages %] <li><a href="[% page.url %]">[% page.title %]</a> [% END %] </ul> [% INCLUDE footer.tt %]

…and the command to generate your output could look something like:

tpage --relative --include_path='relative path/to/header.tt and footer.tt' example.tt

ttree

This requires a bit more setup and can be fiddly at first but is worth it…

Let's assume you're working on a site called trixietang.co.uk and Template::Toolkit has already been installed.

Step 1 - generate base .ttreerc default file

ttree

This will prompt you to create a sample .ttreerc file - optional but useful step to help you understand what the various directives are in Step 3 below.

Step 2 - create site directory structure

~/ |__dist |__templates |__cfg |__trixietang.co.uk |__src |__lib

Step 3 - edit ttree config files

.ttreerc – tweak entries in ~/.ttreerc (or $HOME\.ttreerc if you're on Win32)

# options to rewrite files suffixes (htm => html, tt2 => html) # # suffix htm=html # suffix tt2=html suffix html.tt=html

trixietang.co.uk.conf – create a new file: ~/templates/cfg/trixietang.co.uk.conf and add the following contents:

# options to define dependencies between templates # # depend *=header,footer,menu # depend index.html=mainpage,sidebar # depend menu=menuitem,menubar depend *=header.tt,footer.tt # copy everything except .tt files; those ought to be processed copy = \.(php|pl|cgi|ico|jpg|pdf|scssc|scss|css|map|eot|svg|otf|ttf|wo +ff|woff2|js|ics|less|eps|pdn|tif|xml)$ # directory containing source page templates src = ../trixietang.co.uk/src # directory where output files should be written [~/dist] dest = ../../dist/trixietang.co.uk # additional directories of library templates lib = ../trixietang.co.uk/lib

Step 4 - put include files in ~/templates/trixietang.co.uk/lib

~/ |__dist |__templates |__cfg | |__trixietang.co.uk.conf |__trixietang.co.uk |__src |__lib |__header.tt |__footer.tt

Step 5 - create source template files in ~/templates/trixietang.co.uk/src

~/ |__dist |__templates |__cfg | |__trixietang.co.uk.conf |__trixietang.co.uk |__src | |__example.tt | |__index.html.tt |__lib |__header.tt |__footer.tt

Step 6 - run ttree command from ~/templates/cfg

cd ~/templates/cfg ttree -p -f trixietang.co.uk.conf

If all goes well; you should then see your output files generated under ~/dist/trixietang.co.uk stripped of their tt suffix…

~/ |__dist | |__trixietang.co.uk | |_example | |_index.html |__templates |__cfg | |__trixietang.co.uk.conf |__trixietang.co.uk |__src | |__example.tt | |__index.html.tt |__lib |__header.tt |__footer.tt

Feel free to play around with your ttree config files from Step 3 – altering depends and dest as required.

Good Luck!
Shadowsong


In reply to Re: Can you include templates in Template Toolkit without specifying the file extension? by shadowsong
in thread Can you include templates in Template Toolkit without specifying the file extension? by TrixieTang

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.