A wild question appears!
Trainer sends out Monastery Monk!
The wild question attacks first!

When using HTML::Template along with DBI (and sundry other modules), I ran into an annoying annoyance (hard to believe, I know.)

I have my template set up so that the only variable ('only' meaning 'relating to the annoying annoyance') is the body of the webpage. In other words, the template is the whole HTML file minus the main content (that is, the template has the navigation bar, and so on.)

"Whence do you obtain that sole variable?" asks Monastery Monk.

Ah, good question. I connect to a database that includes (but is not limited to) the main content of every page on the site in a table. This is where problems begin to arise.

But wait! Hold off asking for my codez! Don't bother inquiring about what I use to get this datum! For that is not where the problem lies. The annoyance you keep eagerly hearing is how HTML::Template outputs the main content. Not on the page itself though, no, but in it's source! Because the HTML tags in the variable I retrieve from the table in the database are simply copy/pasted from an actual HTML document, the formatting is all nice, neat, and nested (whilst viewed in a text editor.) In the source of the webpage, the formatting is all wrong! Let me treat you to an example:

<body> <div id="body"> <img alt="alttext" src="/img/heading.gif" /> <div id="extra"><i><font color="#818689" size="4">sometext</font>< +/i></div> <div id="main"> <b class="pagename">Title Text</b> <br /> <br /> <p>Text goes here.</p> <p>More text!</p> <!-- Problem lies here --> <p>MOAR TEXT!!11!!</p> <!-- and here --> </div> </div>

The problem is that the latter paragraphs are not nested properly. Here is my template code:

<body> <div id="body"> <img alt="alttext" src="/img/heading.gif" /> <div id="extra"><i><font color="#818689" size="4">sometext</font>< +/i></div> <div id="main"> <b class="pagename"><TMPL_VAR NAME='PAGENAME'></b> <br /> <br /> <TMPL_VAR NAME='PAGEBODY'> </div> </div>

(Keep in mind I am trying to simplify this as much as possible and still not confuse you.) Let's recap. The template variable 'PAGEBODY' contains the body of the html page, which is the three paragraph tags with text throughout. It looks nested in the template, but does not look nested (thanks for the correction, person who replied saying that I was using the term nested wrong :P) in the source. This is because there are no tabs in the database's version -- there is nothing to make them indented in the source.

So, my question to you, the reader (in case you didn't know what role you played), is How can I get HTML::Template to auto-indent nested variables without editing the variable itself? I am not really sure this can be done, and it would be a shame if that is true because I wasted your time (unless my excellent wit kept you entertained.)


TL;DR? Read the bolded sentence. The rest is filler (though entertaining (to me, at least.))

Update: I suppose it does not really matter if the source looks neat but I feel that the way the source looks represents how I code. It's one of the things I hate about myself xD. I'll probably take ccn's suggestion and move the whole thing over to the left and put an html comment above and below it.

I'm so adjective, I verb nouns!

chomp; # nom nom nom


In reply to Misformatted HTML::Template source code by Lawliet

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.