Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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 ( #585388=note: print w/replies, xml ) Need Help??


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

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.

Replies are listed 'Best First'.
Re^3: HTML::Template : How to separate code and html with lesser maintenance issues
by perrin (Chancellor) on Nov 22, 2006 at 02:34 UTC
    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://585388]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2023-01-31 13:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?