Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: HTML::Template : How to separate code and html with lesser maintenance issues

by perrin (Chancellor)
on Nov 21, 2006 at 19:40 UTC ( #585338=note: print w/replies, xml ) Need Help??


in reply to HTML::Template : How to separate code and html with lesser maintenance issues

It doesn't look like there's a good reason for all three of those to be in the one template. Your example above would be fine and contain no HTML if you made those $html_output assignments call small templates to generate their HTML, rather than in-lining it. Or you could pull the header and footer stuff out into includes, so you'd just call different main templates for each case and they would all make include calls for the header and footer.
  • Comment on Re: HTML::Template : How to separate code and html with lesser maintenance issues

Replies are listed 'Best First'.
Re^2: HTML::Template : How to separate code and html with lesser maintenance issues
by sara2005 (Scribe) on Nov 21, 2006 at 23:32 UTC

    I created some templates like

    small_template.tmpl

    <table align="center"> <tr><td align="center"> <font style="font-size: 14pt; font-family: Arial; solid #CCC; padding: + 3px" color="blue"> <p>Please Select an Item</p></font> </td></tr> </table>

    and then read them into $html_output by

    ... ... open (FILE, "<", "small_template.tmpl" ); $html_output = join "", <FILE>; close FILE; ... ...

    This works great but if I wanted to display some values of variables (like , the selected item's name ) using the small_template.tmpl, it doesn't work.

    Probably, I should have some subrotines to create the html code and then display that using the template. I think it will mix the logic and the html, but it seems inevitable. The best I can do is to have subroutines that create the html messages separated from the logic.

      If you want to display some variables, just run the small templates through HTML::Template instead of reading them directly. There's no reason you can't call it more than once.

        finally, I decided to use separate templates for each of those conditions.

        In this way, my script stays without any html codes.

        Thanks for your help

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://585338]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2023-02-08 23:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (44 votes). Check out past polls.

    Notices?