Gossamer Forum
Home : Products : Links 2.0 : Discussions :

Enchanced template

Quote Reply
Enchanced template
Yes I have read about it the result is

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) = ('', '', '', '', '', '', '', '');
my $result = 0;
# Check for if tags.
$line =~ s/((.*?)$begin\s*if(not)?\s+(.+?)(\s+(<|>|lt|gt|eq|=)\s*(.+?))?$end(.*))/
($orig, $prev, $neg, $var, $full_comp, $comp, $val, $more) = ($1, $2, $3, $4, $5, $6, $7, $8);
# We've found an if tag, let's set the depth to see whether we are in print mode or not.
if ($prev !~ m,$begin\s*endif\s*$end,og) {
$go[$depth] and ($temp .= $prev);
if (!$full_comp) {
if ($neg) { ($self->{'vars'}{$var}) ? ($go[++$depth] = 0) : ($go[++$depth] = $go[$depth]) and ""; }
else { ($self->{'vars'}{$var}) ? ($go[++$depth] = $go[$depth]) : ($go[++$depth] = 0) and ""; }
}
else {
$val =~ s,^['"],,; $val =~ s,['"]$,,;
($comp eq 'eq') and ($result = ($self->{'vars'}{$var} eq $val));
($comp eq '==') and ($result = ($self->{'vars'}{$var} == $val));
($comp eq 'lt') and ($result = ($self->{'vars'}{$var} lt $val));
($comp eq 'gt') and ($result = ($self->{'vars'}{$var} gt $val));
($comp eq '>') and ($result = ($self->{'vars'}{$var} > $val));
($comp eq '<') and ($result = ($self->{'vars'}{$var} < $val));
if ($neg) { $result ? ($go[++$depth] = 0) : ($go[++$depth] = $go[$depth]) and ""; }
else { $result ? ($go[++$depth] = $go[$depth]) : ($go[++$depth] = 0) and ""; }
}
}
else {
# Oops, there was an endif tag we missed, set the original line back and keep going.
$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};
}


Is beyng copied directly over the section called

sub parse {
# ---------------------------------------------------------------
# Parses a template.
#
my $self = shift;
my $template = shift;
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 @lines = split /\n/, $self->{'templates'}{$template};
my $go = 1;

foreach (@lines) {
/$begin\s*if\s*(.+)?\s*$end/o and ($self->{'vars'}{$1} !~ /^\s*$/) ? ($go = 1) : ($go = 0) and next;
/$begin\s*endif\s*$end/o and ($go = 1) and next;
$go or next;
s/$begin\s*(.+?)\s*$end/
if (exists $self->{'vars'}{$1}) {
ref ($self->{'vars'}{$1}) eq 'CODE' ? &{$self->{'vars'}{$1}} : $self->{'vars'}{$1};
}
else {
return "Unkown Tag: $1";
}
/goe;
$self->{'parsed'}{$template} .= $_ . "\n";
}
return $self->{'parsed'}{$template};
}

In the Template.pm file.

Trying to build this however crashes the build process.

I am using Wordpad to edit the file, and am saving it as pure text.

Help?? I would really like to get this feature operational.



Quote Reply
Re: Enchanced template In reply to
The Alex's Enhanced Template.pm (which is available again in the Resources
as "Enhanced Template Support") works very well, at least in my case.

I don't know if the following is your problem, but I think there is a little bug
in the mod: an erroneous "=" instead of "==" in a line of the code.

You can try this:


Code:
# ***************************************** modification - begin ****************

# $line =~ s/((.*?)$begin\s*if(not)?\s+(.+?)(\s+(<|>|lt|gt|eq|=)\s*(.+?))?$end(.*))/

$line =~ s/((.*?)$begin\s*if(not)?\s+(.+?)(\s+(<|>|lt|gt|eq|==)\s*(.+?))?$end(.*))/

# ***************************************** modification - end ******************

Instead, the following lines (some lines further down in the same mod)
are correct now, with "==":


Code:
($comp eq 'eq') and ($result = ($self->{'vars'}{$var} eq $val));
($comp eq '==') and ($result = ($self->{'vars'}{$var} == $val));
($comp eq 'lt') and ($result = ($self->{'vars'}{$var} lt $val));
($comp eq 'gt') and ($result = ($self->{'vars'}{$var} gt $val));
($comp eq '>') and ($result = ($self->{'vars'}{$var} > $val));
($comp eq '<') and ($result = ($self->{'vars'}{$var} < $val));

We can use == for numbers, eq for words, etc.
Quote Reply
Re: Enchanced template In reply to
Thanks I'll try that but am I actually copying and pasting over the right text?



Quote Reply
Re: Enchanced template In reply to
The original mod is at:

Enhanced Template Support!
http://www.gossamer-threads.com/...es/Detailed/877.html

Some other links on this topic:

Enhanced Template.pm
http://gossamer-threads.com/...r=37387&part=all

Resources in Links: Modifications: Version 2.x: Page 2
http://gossamer-threads.com/...rsion_2_x/more2.html

Enhanced Template.pm, missing
http://gossamer-threads.com/...ust&Number=84140

(Now it's again in the Resources).

Quote Reply
Re: Enchanced template In reply to
The sub parse of the mod must replace the sub parse of the admin/Template.pm file.

Quote Reply
Re: Enchanced template In reply to
BTW: The better forum to raise questions like this is in the Links Customization Forum.

Regards,

Eliot Lee
Quote Reply
Re: Enchanced template In reply to
Got to the bottom of the problem. Of Course totally my problem. Does it help to upload the files in ASCII format or what.

Damm it took me hours to find that problem.

Thanks for the help!



Quote Reply
Re: Enchanced template In reply to
In Reply To:
Does it help to upload the files in ASCII format or what.
Yes...it matters...all the files (except the background.gif file) need to be uploaded in ASCII mode.

Regards,

Eliot Lee
Quote Reply
Re: Enchanced template In reply to
I Know I was saying that with a lot of (I should have known better) attached to it.

Thanks for the help the system works really well!



Quote Reply
Re: Enchanced template In reply to
You're welcome.

Regards,

Eliot Lee