Lawliet has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Misformatted HTML::Template source code
by graff (Chancellor) on Nov 01, 2008 at 03:56 UTC | |
|
Re: Misformatted HTML::Template source code
by ww (Archbishop) on Nov 01, 2008 at 12:48 UTC | |
|
Re: Misformatted HTML::Template source code
by shmem (Chancellor) on Nov 01, 2008 at 15:51 UTC | |
by Lawliet (Curate) on Nov 01, 2008 at 18:06 UTC | |
by graff (Chancellor) on Nov 02, 2008 at 00:33 UTC | |
|
Re: Misformatted HTML::Template source code
by ccn (Vicar) on Nov 01, 2008 at 06:56 UTC | |
|
Re: Misformatted HTML::Template source code
by Anonymous Monk on Nov 01, 2008 at 04:08 UTC | |
|
Re: Misformatted HTML::Template source code
by graff (Chancellor) on Nov 02, 2008 at 00:53 UTC | |
by Lawliet (Curate) on Nov 02, 2008 at 01:07 UTC |