Gossamer Forum
Home : Products : Links 2.0 : Customization :

Nested file include?

Quote Reply
Nested file include?
I would like to use nested file include in my templates.
I tried it, but it doesn't work. I get the error: "Unkown Tag: include banner.html".
Here's what I did:
I used <%include header.html%> in home.html.
Then I used <%include banner.html%> in header.html.
On the home.html I got the error: "Unkown Tag: include banner.html"

Doesn't support the Enhanced Template Support the nested includes???
If it doesn't, how can I modify it, to support nested includes???

Thanks in advance,
Webmaster33

Quote Reply
Re: Nested file include? In reply to
In Reply To:
Doesn't support the Enhanced Template Support the nested includes???
Nope.

In Reply To:
If it doesn't, how can I modify it, to support nested includes???
Not quite sure...


Regards,

Eliot Lee
Quote Reply
Re: Nested file include? In reply to
Well, I checked the template.pm.
The "nested if" feature is very similar what I would like.
The "nested include" should be similar like this "nested if" code part:
Code:
# 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 ""; }
}
}

... etc ...
If there is a perl expert out there, I'm sure he can code the "nested include" feature within no time.
If anybody can help coding this feature, please help me.

Thanks,
Webmaster33
Quote Reply
Re: Nested file include? In reply to
Here's a mod from the dbman forum, maybe you can make it work here:

sub include {
# --------------------------------------------------------
# This is text to include. Use like an SSI.

my $file = shift;
open (FILE, "<$file") or die "Can't open $file ($!)";
print <FILE>;
close FILE;
}

## Then add this line wherever you want file included
## |; &include ("../path/to/file"); print qq|


Quote Reply
Re: Nested file include? In reply to
Well, Sigrid, this is not what I was looking for.
I use templates.
The code you provided does support an SSI-like file include, but it doesn't work with templates.
To support nested includes in templates, is a bit more complicated.
Thanks, anyway!

Any other ideas?

Webmaster33

Quote Reply
Re: [webmaster33] Nested file include? In reply to
The extended template parser at http://www.gossamer-threads.com/...es/Detailed/877.html uses a single Perl substition to perform all includes. By using a while statement, this can be repeated to process nested include files. Change this:

Code:
# 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;

to this (changes shown in bold red):

Code:
# Parse includes, do this first so that the includes can include
# template tags.
while ($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) {}