I wrote a conversion utility the other day for a colleague. It takes an Excel spreadsheet (top forty music chart) and transforms it into a webpage.

My colleague was very happy, and I then I showed her the template. "It uses a very simple template language..." I said, and saw the look on her face. She does not want to learn another template language.

So, here's the thing. In HTML::Template you do it one of two different ways. You either have code like this:

<tmpl_loop name="chart"> <tr> <td><tmpl_var name="chartposition"></td> <td><tmpl_var name="artist"></td> <td><tmpl_var name="song"></td> </tr> </tmpl_loop>

or you have code like this:

<!--tmpl_loop name="chart" --> <tr> <td><!-- tmpl_var name="chartposition" --></td> <td><!-- tmpl_var name="artist" --></td> <td><!-- tmpl_var name="song" --></td> </tr> <!--/tmpl_loop -->

but in neither case do you have actual working HTML. It's not valid in the first case, and the second case, while valid, doesn't render anything in the browser.

What my friend the busy web-developer would certainly prefer is if she could code up a web page like this:

<tr (repeat this row for each song please)> <td>number</td> <td>band name</td> <td>song name</td> </tr>

But obviously, that isn't valid HTML exactly either. So, I had what's either a brainwave or it's not, but everyone in these days of HTML 4 is already adding arbitrary markers to their HTML anyway. The classes (or IDs).

My friend will have to add a class here or there anyway, just to get the CSS right, and it really doesn't much matter what they're called.

So why can't we have a version of HTML::Template which works something like this?

<tr class="tmpl-loop-chart"> <td class="tmpl-var-chartposition">1</td> <td class="tmpl-var-bandname">OUTKAST</td> <td class="tmpl-var-songname">Roses</td> </tr>

That is, one where the developer could make up a template with any old content in it they wanted, and the module would parse the HTML and figure out that the loop ended with the next (balanced) </tr> tag, the TDs close with the next (balanced) </td> tag and so on, and replace the content of that tag with the data, rather than the artificial template-language tag which the developer has to learn.

What do fellow monks think?



($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss')
=~y~b-v~a-z~s; print

In reply to Thinking Aloud About HTML::Template by Cody Pendant

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.