Unlike the many HTML::Template and CGI::Fasttemplate followers, I designed a similar system using Text::Template. My site, however, involved only a few templates for many layers. (e.g. Home page, 2nd-level pages (any any deeper)). The goal was to separate the site into three parts: Content, for non-computer people to edit. TEmplates, for interface people to edit, and code, for programmers.
It works like this:
- I have a database holding the info for all the pages (title, name, Keywords for meta tags, and parent-child relationships.) The database isn't vital to the concept, but lets us modify the site structure easily.
- I have a small script that consists of two subroutines, one that loads all variables for a given page from the database, and another that uses Text::Template to load a given file. I use the prepend option of Text::Template to load that template with this very script (So my templates can in turn call templates, etc)
- Actually, I have several variants on #2, each with a slightly different purpose. One writes an HTML file (or multiple files). One displays the content parsed into HTML, but without writing a static HTML file, another does the same thing, but wraps the text of the content in TEXTAREA fields so it can be edited, etc..
The result is two-fold. The goal of separation has occured, allowing us to quickly re-build and add onto parts of the site. Also, because there is a difference between the base content files and the actual "built" HTML files, we have an effective Staging Area for content to be reviewed and approved before going Live. Combining this last part with some simple RCS has given us a measure of control and version history as well. Also, we can simply point our build script at a different set of templates, and generate a sub-site that is (for example) for text-only. No need to duplicate content.
In case you are curious, Content pages look like this:
<!!&SiteBuilder_Load($Header,$ID)!!>
Uneditable content
<!!$BeginText!!>
Editable Content
<!!$EndText!!>
more uneditable content
<!!&SiteBuilder_Load($Trailer, $ID)!!>
(<!! and !!> are the tags I choose for Text::Template)
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.