Gossamer Forum
Home : Products : Links 2.0 : Customization :

What's wrong with my template.pm?

Quote Reply
What's wrong with my template.pm?
I have copied all the code in http://www.gossamer-threads.com/scripts/resources/Detailed/877.html
CGI ERROR
==========================================
Error Message : fatal error: /home/mysite/cgi-bin/dir/admin/Template.pm has too many errors.
Script Location : /home/mysite/cgi-bin/dir/admin/nph-build.cgi
Perl Version : 5.00503

---Parser---

sub parse {
# ---------------------------------------------------------------
# Parses a template.
#
my ($self, $template) = @_;
my $begin = $self->{'begin'} || quotemeta('<%');
my $end = $self->{'end'} || quotemeta('%>');
exists $self->{'templates'}{$template} or ($self->load_template($template) or return undef);
exists $self->{'vars'} or ("error ('NONAMESPACE') and return undef);
$self->{'parsed'}{$template} = '';
my $temp = $self->{'templates'}{$template};
# Parse includes, do this first so that the includes can include
# template tags.
$temp =~ s#$begin\s*include\s*(.+?)\s*$end#
if (exists $self->{'inc'}{$1}) { $self->{'inc'}{$1}; }
else {
if (open (INC, "${$self}{'ROOT'}/$1")) {
$self->{'inc'}{$1} = join ("", <INC> );
close INC;
$self->{'inc'}{$1};
}
else {
"Can't find file: ${$self}{'ROOT'}/$1";
}
}
#goe;
# Now go line by line and strip out the unwanted stuff looking for
# if and ifnot tags.
my @lines = split /\n/, $temp;
$temp = ''; my @go = (1,1); my $depth = 1; my $line = '';
LINE: foreach $line (@lines) {
# Init the previous, variable and more strings.
my ($prev, $var, $neg, $more, $orig, $full_comp, $comp, $val, $key) = ('') x 9;
my $result = 0;
my $ret = '';
# Check for if tags.
$line =~ s/^((.*?)$begin\s*(if(?:not)?|unless)\s+(.+?)(\s*(<|<=|>|>=|\slt\s|\sle\s|\sgt\s|\sge\s|\seq\s|==?)\s*(.+?))?$end(.*))/
($orig, $prev, $neg, $var, $full_comp, $comp, $val, $more) = ($1, $2, $3 ne "if", $4, $5, $6, $7, $8);
if ($prev !~ m,$begin\s*endif\s*$end,og) {
defined $val or ($val = '');
$val =~ tr,'",,d;
$val = $self->_check_func ($val, $strict, 1);
$key = $self->_get_value ($var, 0); # No strict as we are comping.
$go[$depth] and ($temp .= $prev);
if (!$full_comp) {
if ($neg) { $key ? ($go[++$depth] = 0) : ($go[++$depth] = $go[$depth]) and ($ret = ''); }
else { $key ? ($go[++$depth] = $go[$depth]) : ($go[++$depth] = 0) and ($ret = ''); }
}
else {
CASE: {
$comp =~ s,^\s+|\s+$,,g;
($comp eq 'eq') and $result = ($key eq $val), last CASE;
($comp eq '=' or $comp eq '==')
and $result = ($key == $val), last CASE;
($comp eq 'lt') and $result = ($key lt $val), last CASE;
($comp eq 'le') and $result = ($key le $val), last CASE;
($comp eq 'gt') and $result = ($key gt $val), last CASE;
($comp eq 'ge') and $result = ($key ge $val), last CASE;
($comp eq '>' ) and $result = ($key > $val), last CASE;
($comp eq '>=') and $result = ($key >= $val), last CASE;
($comp eq '<' ) and $result = ($key < $val), last CASE;
($comp eq '<=') and $result = ($key <= $val), last CASE;
};
if ($neg) { $result ? ($go[++$depth] = 0) : ($go[++$depth] = $go[$depth]) and ($ret = ''); }
else { $result ? ($go[++$depth] = $go[$depth]) : ($go[++$depth] = 0) and ($ret = ''); }
}
$ret;
}
else {
$more = '';
$orig;
}
/oe;
if ($more) { $line = $more; redo LINE; }
# Check for endif tags.
$line =~ s/^(.*?)$begin\s*endif\s*$end(.*)/
($prev, $more) = ($1, $2);
$go[$depth] and ($temp .= $prev);
$go[$depth--] = 1;
"";
/oe;
if ($more) { $line = $more; redo LINE; }
# Add the content..
$go[$depth] and ($temp .= "$line\n");
}
# Replace the special variables, we allow code ref mapping.
$temp =~ s/$begin\s*(.+?)\s*$end/
if (exists $self->{'vars'}{$1}) {
ref ($self->{'vars'}{$1}) eq 'CODE' ?
"{$self->{'vars'}{$1}}($self->{'vars'}) : $self->{'vars'}{$1};
}
else { "Unkown Tag: $1"; }
/goe;
$self->{'parsed'}{$template} = $temp;
return $self->{'parsed'}{$template};
}

Help again!!

Quote Reply
Re: What's wrong with my template.pm? In reply to
Help Help....why nobody anwser me..................... :(

Quote Reply
Re: What's wrong with my template.pm? In reply to
Try the following:

1) Delete the sub parse in your ORIGINAL Template.pm file.

2) Then add the codes from the Modification page.

3) Then try to re-build your directory.

And to check the exact "syntax errors" of the Template.pm file, do the following:

1) Connect to your account via telnet.
2) At the command prompt, type in the following command:

Code:

cd /cgi-bin/links/


3) Check the syntax of the Template.pm file:

Code:

perl -c Template.pm


Then report syntax errors you receive in this Thread.

Regards,

Eliot Lee
Quote Reply
Re: What's wrong with my template.pm? In reply to
I can't use telnet in my web host.
Actually i already delete the sub parse in my original file. Then copy the whole code from Resources Centre and Paste into the template.pm. That's all.
Thanks..Eliot...

Quote Reply
Re: What's wrong with my template.pm? In reply to
Well, do you have access to your Perl Error Log? If so, readn them!

Regards,

Eliot Lee
Quote Reply
Re: What's wrong with my template.pm? In reply to
Hi Eliot,
I appear to experiencing the same problem when I replace the sub parse code in the "Template.pm" file with the enhanced template code. I do have telnet access to my server and did as you instructed in another thread. The results are as follows:

Global symbol "temp" requires explicit package name at Template.pm line 114.
Scalar found where operator expected at Template.pm line 122, at end of line
(Missing operator before ?)
syntax error at Template.pm line 122, near "if (open (INC, "$"
Global symbol "self" requires explicit package name at Template.pm line 122.
Scalar found where operator expected at Template.pm line 128, at end of line
(Missing operator before ?)
syntax error at Template.pm line 128, near ""Can't find file: ${$self}{'ROOT'}/$
1"
String found where operator expected at Template.pm line 143, near "($orig, $pre
v, $neg, $var, $full_comp, $comp, $val, $more) = ($1, $2, $3 ne ""
(Might be a runaway multi-line "" string starting on line 128)
(Missing semicolon on previous line?)
In string, @lines now must be written as \@lines at Template.pm line 128, near "
;
}
}
#goe;
# Now go line by line and strip out the unwanted stuff looking for
# if and ifnot tags.
my @lines"
Global symbol "lines" requires explicit package name at Template.pm line 128.
In string, @go now must be written as \@go at Template.pm line 128, near "$temp
= ''; my @go"
Global symbol "go" requires explicit package name at Template.pm line 128.
Global symbol "depth" requires explicit package name at Template.pm line 128.
Global symbol "line" requires explicit package name at Template.pm line 128.
Global symbol "prev" requires explicit package name at Template.pm line 128.
Global symbol "var" requires explicit package name at Template.pm line 128.
Global symbol "neg" requires explicit package name at Template.pm line 128.
Global symbol "more" requires explicit package name at Template.pm line 128.
Global symbol "orig" requires explicit package name at Template.pm line 128.
Global symbol "full_comp" requires explicit package name at Template.pm line 128
.
Global symbol "comp" requires explicit package name at Template.pm line 128.
Global symbol "val" requires explicit package name at Template.pm line 128.
Global symbol "key" requires explicit package name at Template.pm line 128.
Global symbol "result" requires explicit package name at Template.pm line 128.
Global symbol "ret" requires explicit package name at Template.pm line 128.
Global symbol "begin" requires explicit package name at Template.pm line 128.
Global symbol "end" requires explicit package name at Template.pm line 128.
Bareword "d" not allowed while "strict subs" in use at Template.pm line 146.
Global symbol "strict" requires explicit package name at Template.pm line 147.
syntax error at Template.pm line 173, near "}"
Template.pm has too many errors.

-----------------------------------------------------------

Any help you can provide is greatly appreciated.

Thank you, Wes

Quote Reply
Re: What's wrong with my template.pm? In reply to
I found the log file.
--Code Error--
exists $self->{'vars'} or ("error ('NONAMESPACE') and return undef');

--Change to this --
exists $self->{'vars'} or ("error ('NONAMESPACE') and return undef");

AND
--Code Error--
$val =~ tr,'",,d;

---change to ---
$val =~ tr,'',,d;

Am I right??
Eliot...Thanks again!



Quote Reply
Re: What's wrong with my template.pm? In reply to
Eliot,
I still cannot solve the problem....i got the same error with wzastrow! exactly same as wzastrow's error message. is it really got errors in this mod ? if yes, better correct the code in this mod in Resources Centre to prevent the case happen same as wzastrow and me...anyway Eliot ..thanks for your help. I really appreciate...
How's about this line??

--Code---

ref ($self->{'vars'}{$1}) eq 'CODE' ?
"{$self->{'vars'}{$1}}($self->{'vars'}) : $self->{'vars'}{$1};

is it wrong too??

Thanks for help.

Quote Reply
Re: What's wrong with my template.pm? In reply to
I copied the CODES as is from the Resource Center and guess what, THEY WORK! Tongue

Probably a problem with the text editor you are using...use TextPad or WordPad...if you use other text editors, there is a chance that the codes you copied became corrupted in the process of installing them in the Templates.pm file.

In Reply To:
if yes, better correct the code in this mod in Resources Centre to prevent the case happen same as wzastrow and me
Don't tell me...report the bug to Gossamer Threads whom I am NOT associated with.

Regards,

Eliot Lee
Quote Reply
Re: What's wrong with my template.pm? In reply to
Eliot,
i'm using notepad in windows 98. I think it should me ok...
Sorry...Eliot...could send me the template.pm to me...(search@bpost.net) i will really appreciate it..........
Thanks again......

Regards,
Will

Quote Reply
Re: What's wrong with my template.pm? In reply to
Hello !!!

I'm having the same problems whith this codes.

If somebody have the Template.pm working please send me it for a test. marcoa@onda.com.br

I sent a e-mail to Alex and I'm waiting for his help.


Regards,

marcoBR

Quote Reply
Re: What's wrong with my template.pm? In reply to
Could this be the problem? I saw this in another post somewhere last night. But I don't seem to have this on the bottom of the template.pm file.


sub DESTROY {
# ---------------------------------------------------------------

}

1;

Quote Reply
Re: What's wrong with my template.pm? In reply to
I also have the same problem. I would be very glad to get
some help or working template file. Thanks.

Peter Jonas

Quote Reply
Re: What's wrong with my template.pm? In reply to
If i get any solution... i will distribute the file to you all...but i still didnt get any reply yet....

Quote Reply
Re: What's wrong with my template.pm? In reply to
hello again !!!

I have certainty that the code of the Enhanced Template Support in the Resource Center are wrong whith coarse errors.

I got a working version of enhanced Template.pm and you can download it at http://www.maringanetshop.com.br/Template.txt

I'm yet having some problems whith this version ... but I not be sure why ... please look this codes:

My category.html template eg.

Code:
<html>
<head>
</head>
<body>
<%if tdc%>
<div align="center">
<center>
<table border="0" width="440" cellspacing="0" cellpadding="0">
<tr>
<td width="100%">
<p align="center">

<font face="arial" size="3">
<u><b><%tdc%></b></u></font>
</td>
</tr>
</table>
</center>
</div>
<%endif%>
<div align="center">
<center>
<table border="0" width="440" cellspacing="0" cellpadding="0">
<tr>
<td width="100%">
<p align="center"><%Texto%></td>
</tr>
</table>
</center>
</div>
</body>
</html>
Before I installed this version of Template.pm the <%if %>
statament was working perfectly ... then in the eg. above if exist a product the entire block of table are printed until the end of the html.

After I installed it, if exist a product the entire code are printed, but if not exist the code are be broking in
<%endif%> tag when the correct would be print until the end
of the html ...


I'm going crazy !!!


Please, report me if the same problem are happening whith you ...


Best Regards,

marcoBR


btw: sorry 4 my english ...

Quote Reply
Re: What's wrong with my template.pm? In reply to
Hi,

I just wanted to thank you for posting a working Template.pm file.

I'm having a little problem of my own. I used to be able to use a search word "test" and results used to show up with that word highlighted. Even a partial word like conTEST.

Now all that shows up is "Your search returned 8 links" and then nothing after that. The skinny little table area at the bottom that used to be there is gone too.

Is that what you were trying to say? Same problem?

Liz

Quote Reply
Re: What's wrong with my template.pm? In reply to
Thanl you v e r y much for the working template. It works fine (so far).

Greetings from berlin

Torsten Trebess
Quote Reply
Re: What's wrong with my template.pm? In reply to
oh life, oh bad luck ... not today !!!

The codes above are working perfectly for me now ... I found a mistake in my codes. (stupid bit)

Hey, is it possible to compare pieces of strings???

eg:

<%if category_name eq '/^Test/'%> or

<%if category_name =~ /^Test/%>

which would be the correct code ???


Regards,

marcoBR

Quote Reply
Re: What's wrong with my template.pm? In reply to
 

I have this in my search_results.html
-----------------snip-------------------------------
<font face="Arial" color="#000000">Your search returned
<strong><%link_hits%></strong> Links.</font>
<%if next%>
<%if link_results%>
<h2><font size="2" face="Arial" color="#000000">Links:</font></h2>

<p><%link_results%>

<%endif%>

<%if prev%>

<%prev%>

<%endif%>

<%if next%>

<%next%>

<%endif%>

----------------------------------------------
I'm far from knowing alot about this stuff, but I was thinking maybe the code that needs to be added somewhere in there is:

<%category_results%>?

Think that will work?

I tried to go to your website to have a look, but I wasn't able to get it loaded. I guess you must be working on it or the server is down. I'll try again later.

ttyl,
Liz



Quote Reply
Re: What's wrong with my template.pm? In reply to
errr...Rather

<P><%category%> or <p><%category_results%>

::Shrug:: lol!

I'll have to look into this more and see what else I can up up with.

ttyl,
Liz

Quote Reply
Re: What's wrong with my template.pm? In reply to
ok thriftysearch,

All the <%if %> statament must have a <%endif%> to work properly. Laugh


Please gurus, help me whith my last post above.

In Reply To:
<%if category_name eq '/^Test/'%> or

<%if category_name =~ /^Test/%>
Is it works ??? ... Which code is correct ??? ... Crazy


Best Regards,

marcoBR

Quote Reply
Re: What's wrong with my template.pm? In reply to
hum ... I will try to explain my case for you !


I have only one category.html template to facility my job, then all statament must be put in this template eg:

<%if category_name eq 'Soccer'%>
<%links%>
<%endif%>

<%if category_name eq 'Beach_Volley'%>
<%links%>
<%endif%>

... in this case I have subcategories under Soccer and Beach Volley categories, but the links are not showed for them.

maybe ... which regular expression we could use to match the categories whith all his subcategories ???


Can you understand me now ??? What do you think ???


obs: I don't want to use multiple categories templates!!!


Regards,

marcoBR


Quote Reply
Re: What's wrong with my template.pm? In reply to
Come on perl gurus ... help me please !!!