I am using the template example in the Perl Cookbook to dynamically generate pages. I have looked into Template::Toolkit, but I'm uncertain whether or not it will be available on the server my Perl code is to run on.

The template example in the Perl Cookbook should be more than sufficient. My dilemma, however, is determining the best way to use it. I am going along with using %%ABC%% placeholders to swap out things generated by my Perl code. My goal is to keep ALL HTML code out of my Perl script so that any design modifications can be done via the external template files.

My current setup is to have two template files for a single page. The first template page contains all of the HTML code to create the bulk of the page and two placeholders, %%PAGETITLE%% and %%MAIN%%. %%MAIN%% is the placeholder for the page content.

[html] [body] [table] [tr] [td] [table] %%MAIN%% [/table] [/td] [/tr] [/table] [/body] [/html]
The second template file would contain how the contents of that page should be formatted. This should only consist of [tr] and [td]tags.

[tr] [td]%%VAL1%%[/td] [td]%%VAL2%%[/td] [td]%%VAL3%%[/td] [/tr]
So, my Perl code would fill in the placeholders of the second template file. Grab that, and stick it in the first template file as the %%MAIN%% placeholder.

Hopefully this makes sense. Is this a good approach? Any better suggestions for keeping all HTML code out of my Perl script?

In reply to HTML templates => no HTML in Perl code by emilford

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.