http://qs321.pair.com?node_id=585338


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