MrMadScience has asked for the wisdom of the Perl Monks concerning the following question:

I'm working with some code that was left by a no longer existent programmer that was written using HTML:Template.
The code peices I am working with deal with how we display BLAST information for sequence alignment reports.
My interest with this comes from how we display these reports, whether they are for individual sequences or assembled sequences.
In the case of an assembled sequence, a template variable

 <TMPL_VAR NAME="contig"> would be used to identify the correct report.

However, the display page itself is not currently concerned with the existence of that variable, as the display formatting is done by a couple of other scripts. I tried using

<TMPL_IF NAME="contig"> to decide if it exists, but it doesn't seem to work, the

<TMPL_ELSE> loop is used instead.

Any feedback would be much appreciated!

Replies are listed 'Best First'.
Re: HTML:Template
by b10m (Vicar) on Jan 23, 2004 at 17:37 UTC

    After reading your post four times, I still don't quite get what you're asking for, but I try to be as much of a help as possible. It would be really helpful if you could post a snippet of what you've tried, the "errors" and what you'd like it to do ;)

    If I understand correctly, you have a script ready to pump out some data to HTML::Template templates. And, you want to add one variable (named "contig") to some template.

    First of all, you need to set this variable within your Perl script:

    $template->param(CONTIG => 1);

    After that, you can build the if-statement in the template like this:

    <TMPL_IF NAME="CONTIG"> ... do something, if CONTIG is true ... <TMPL_ELSE> ... do something when CONTIG is false ... </TMPL_IF>

    jeffa wrote a nice tutorial (HTML::Template Tutorial) which may help you out, but the POD (HTML::Template) is quite readable as well and offers a little more information.

    HTH

    --
    b10m
Re: HTML:Template
by dws (Chancellor) on Jan 23, 2004 at 19:14 UTC
    I'm with b10m on this. After reading the post through several times, I have to make several assumptions for the question to make sense. It would really help to rephrase your problem statement, specifically calling out what you expect (or desire) to happen, and what you are actually observing. "[I]t doesn't work" isn't enough to go on without a statement of what "working" means, and some indication of what you're seeing instead. It would also help to post a code fragment that demonstrates the problem, though if you're in over your head on someone else's code, this may be a challenge.

    If you have a construct that looks like

    <TMPL_IF NAME="contig"> abc <TMPL_ELSE> xyz </TMPL_IF>
    then the ELSE part will be expanded if contig holds a "false" value (i.e., if it holds undef, an empty string, or zero).

Re: HTML:Template
by MrMadScience (Acolyte) on Jan 23, 2004 at 19:22 UTC
    My most humble replies for my shoddy writing on the problem statement.
    I guess I need to slow down when I'm posting to make this make some sense.
    However, the first reply hit the problem. I didn't realize that the TMPL_VAR "contig" wasn't being defined in the last script that ran prior to the template.
    So I then altered that perl script to define it based on what was passed to it and all was good.
    I'll try to be more clear next time I fumble in perl.
Re: HTML:Template
by MidLifeXis (Monsignor) on Jan 23, 2004 at 19:07 UTC

    Not quite following your question, but...

    • Check to see if you are checking for the variable inside of a TMPL_LOOP. By default, variables are localized, and variables from an outer scope will not be included in your current scope (see global_vars)
    • TMPL_IF does not check for existance, it checks for perl's definition of true.

    --MidLifeXis