Gossamer Forum
Home : Products : Links 2.0 : Customization :

Using Includes but not wanting to use the dptemplate path

Quote Reply
Using Includes but not wanting to use the dptemplate path
I'm using the enhanced Template code
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;

This code lets me use Includes filename, where filename is located in the path defined as root (my template path). I want to modify this code so that is looks in two places. It firsts looks in the templates folder. If the template is not found, it then looks in a different folder in my html directory. If that is not found, then there is an error.

So I want to modify the above code so that I can define a variable as a second path and have the code check for the included file in each path.

The reason I want to do this is I use standard includes in my pages. They are all referenced on non-Links pages by a URL pointing to an inc folder in my html directory. I don't want to have to duplicate these includes and stick them in my templates directory (and dont want to move my regular templates outside of the templates directory)

Help anyone?
Quote Reply
Re: [astrometro] Using Includes but not wanting to use the dptemplate path In reply to
Are your pages using SSI? If so, you can just use the include in your Links2 template, but reference the non-Links2 file you want included.

If not, then it seems an elsif would work:

# 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};
}

elsif (open (INC, "${$self}{'/path/to/www'}/$1")) {
$self->{'inc'}{$1} = join ("", <INC> );
close INC;
$self->{'inc'}{$1};
}
else {
"Can't find file: ${$self}{'ROOT'}/$1";
}
}
#goe;



Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] Using Includes but not wanting to use the dptemplate path In reply to
I am not using SSI, although maybe that is the way to go.


I did try exactly what you suggested but it seems not to work - and no clue why....
Quote Reply
Re: [astro] Using Includes but not wanting to use the dptemplate path In reply to
Did more testing and just replacing ROOT in "${$self}{'ROOT'}/$1")) does not do it.

I'm not at all understanding what self and ROOT do in this context to be able to change them, but they are not simple variables that you can just swap out with a path setting.

So modifying this is more complex. ANy clues?
Quote Reply
Re: [astro] Using Includes but not wanting to use the dptemplate path In reply to
Solution!:

if (open (INC, "path/to/includes/$1")) {
$self->{'inc'}{$1} = join ("", <INC> );
close INC;
$self->{'inc'}{$1};
}
else {
"Can't find file: ${$self}{'ROOT'}/$1";
}