Re: [htmltmpl] Comparing H::T:Expr variables
Brought to you by:
samtregar
From: Mathew R. <mat...@re...> - 2003-11-20 05:13:44
|
Hi Chris, I am assuming that this snippets of script/template are not exactly the = same as your real code? If so, you reeeealllly should be calling 'use strict;' since I can see = that there are vairable definitions here that are not declared before = use. Perl will quite happily do this, thus auto-vivifying some of these = variables into globals - probably not what you really want to happen. Also, didn't you say that you were using HTML::Template::Expr > my $template =3D HTML::Template->new(filename =3D> 'index.tmpl', = strict =3D> 0,global_vars =3D> 1); > I really dont know why H::T is complaining about finding a <//TMPL_IF> > without a <TMPL_IF>, since there is, indeed one there. This complaint was because I told you to use "strict =3D> 0" thus H::T = is ignoring the <TMPL_IF EXPR....>, thus hitting the </TMPL_IF> without = finding the <TMPL_IF...>. Ignore this - this was expected, and thus = confirmed that the error was with the TMPL_IF. Try using H::T::E rather than H::T ? Mat > I will include my HTML template and source: >=20 > HTML Template: > <TMPL_LOOP ROWS> > <br> > <br> > <TMPL_VAR NAME=3DMODEL_NAME> > <br> > <img src=3D"<TMPL_VAR NAME=3DMODEL_THUMB>" border=3D0 = height=3D100 width=3D100> > <br> > Can be seen at: > <TMPL_LOOP URLLOOP> > Model Name: <TMPL_VAR NAME=3DMODEL_NAME> > Model Comp: <TMPL_VAR NAME=3DMODEL_COMP> > <TMPL_IF EXPR=3D"MODEL_COMP eq MODEL_NAME"> > Model Name: <TMPL_VAR NAME=3DMODEL_NAME> > Model Comp: <TMPL_VAR NAME=3DMODEL_COMP> > The URL on match: <TMPL_VAR NAME=3DMODEL_URL> > </TMPL_IF> > </TMPL_LOOP> > </TMPL_LOOP> > <br> >=20 >=20 > The Perl Script: > #!/usr/bin/perl > use DBI; > use CGI; > use HTML::Template; > use HTML::Template::Expr; >=20 > my $dbsource =3D "DBI:mysql:dbname=3Dmsearch;host=3Dlocalhost"; > my $dbuser =3D "chrisp"; > my $dbpasswd =3D "xxxxxxxx"; >=20 > my $template =3D HTML::Template->new(filename =3D> 'index.tmpl', = strict =3D> 0, global_vars =3D> 1); > my $bychar =3D 'c'; > my @URLS =3D (); > my @ROWS =3D (); >=20 > my $dbh =3D DBI->connect($dbsource, $dbuser, $dbpasswd); > my $dbh2 =3D DBI->connect($dbsource, $dbuser, $dbpasswd); >=20 > my $query =3D "SELECT DISTINCT model_name as model_name, model_thumb = FROM models WHERE model_firstchar =3D '$bychar' GROUP BY model_name"; > my $sth =3D $dbh->prepare($query); > $sth->execute() || die &error($DBI::errstr); >=20 > while (my $data =3D $sth->fetchrow_hashref) { > $model_name =3D $data->{model_name}; >=20 > my $query2 =3D "SELECT model_url FROM models where model_name = =3D '$model_name'"; > my $sth2 =3D $dbh2->prepare($query2); >=20 > $sth2->execute(); > $sth2->bind_columns(undef, \$model_url); >=20 > while($sth2->fetch()) { > push (@URLS, > { > MODEL_URL =3D> $model_url, > MODEL_COMP =3D> $data->{model_name} > } ); > } >=20 > push (@ROWS, > { > MODEL_NAME =3D> $data->{model_name}, > MODEL_THUMB =3D> $data->{model_thumb}, > URLLOOP =3D> \@URLS, > } > ); > } >=20 > $sth->finish(); >=20 > $template->param( ROWS =3D> \@ROWS ); > print $template->output; >=20 |