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

Re: Re: rant on = qw(HTML::Mason Embperl Template etc) ;

by kwoff (Friar)
on Nov 10, 2001 at 05:56 UTC ( #124525=note: print w/replies, xml ) Need Help??

in reply to Re: rant on = qw(HTML::Mason Embperl Template etc) ;
in thread rant on = qw(HTML::Mason Embperl Template etc) ;

One thing I didn't like about HTML::Template (maybe I just didn't understand it enough to come up with a clean solution) was the following.

I wanted to give the HTML developers a set of variables that they could use. They could pick and choose which of the set they wanted to display. It was a snippet of HTML to display the current weather, so they could show "wind speed", "wind direction", "temperature", "humidity", and so on.... I did something like:

$tmpl = HTML::Template->new('filename' => $TEMPLATE); $tmpl->param('Temperature' => $current->{'Temperature'}); $tmpl->param('WindDirection' => current->{'WindDirection'}); $tmpl->param('WindSpeed' => $current->{'WindSpeed'}); ... print $tmpl->output();

and the HTML developers would ideally be able to select from those variables and use them like this:

<TABLE> <TR> <TD> <SPAN CLASS="weather-temp"> <!--TMPL_VAR NAME="Temperature"-->&deg;F </SPAN> </TD> </TR> </TABLE>

But actually what I had to do was put ALL the variables into the template, and hide them as a comment, otherwise I would get some error:

<H3>Current weather</H3> [insert HTML here using a selection of the variables below] <!--DO NOT REMOVE:<!--TMPL_VAR NAME="Temperature"--><!--TMPL_VAR NAME= +"PerceivedTemperature"--><!--TMPL_VAR NAME="R elativeHumidity"--><!--TMPL_VAR NAME="WindDirection"--><!--TMPL_VAR NA +ME="WindSpeed"--><!--TMPL_VAR NAME="Pressure" --><!--TMPL_VAR NAME="Visibility"--><!--TMPL_VAR NAME="Icon"--><!--TMP +L_VAR NAME="IconDescription"-->--> ...

and I just find that extremely ugly. What's more, if your variables are within a TMPL_LOOP (which I also did a list of news headlines, so in fact I found myself in that situation), then you have to put that blob of commented-out TMPL_VARs inside that loop.

Also I found that somehow this setup was confusing to the HTML designers, so I ended up having to edit the HTML anyway (maybe that's unique to my situation, though), thus smashing my dreams of never having to look at the HTML again.

Replies are listed 'Best First'.
Re: Re: Re: rant on = qw(HTML::Mason Embperl Template etc) ;
by maverick (Curate) on Nov 10, 2001 at 06:05 UTC
    There is an option to allow exactly what you're looking for. In fact it's one I ALWAYS have set. From the docs:

    die_on_bad_params - if set to 0 the module will let you call $template->param(param_name => 'value') even if 'param_name' doesn't exist in the template body. Defaults to 1.

    Change your constructor to

    $tmpl = HTML::Template->new('filename' => $TEMPLATE, 'die_on_bad_params' => 0 );
    And you'll be good to go.

    perl -l -e "eval pack('h*','072796e6470272f2c5f2c5166756279636b672');"

      Excellent, thanks.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://124525]
[1nickt]: Tux I'm getting there ... perlbrew list | wc -l 22 :-)

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2017-09-21 02:23 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (241 votes). Check out past polls.