Gossamer Forum
Home : Products : Links 2.0 : Customization :

Include Pages in Different Directories

Quote Reply
Include Pages in Different Directories
I installed the "include mod" from: http://www.gossamer-threads.com/scripts/resources/Detailed/877.html
to allow me to include other pages into the templates. However, the script now is looking in the templates directory for the included files. My include files are in puplicDocs/include_files/ and not in puplicDocs/cgibin/links/admin/templates (the default templates directory).
1. Where should I modify the mod to make it look for the include files in another directory ?
2. Also, can I still have the <html><head></head><body></body></html> tags in the files, as this is required for other pages in my site (call the include file *.html) ...
thank you for ur help
Mark
Quote Reply
Re: [Mark2] Include Pages in Different Directories In reply to
As far as I know, the included files need to be in the template directory.
Your included files can have the tags you mentioned, but it will make for poor code (pages will not validate, and may not render well in some browsers).

What type of files are you wanting to include?


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] Include Pages in Different Directories In reply to
Thanks Leonard for your reply.
I am trying to include html files in my templates. I chose them to be html because front page can not read txt files (no head and body tags) correctly. Therefore, i have to make them html files to be included into the templates set and to the html front page files.
Thanks
Mark
Quote Reply
Re: [Mark2] Include Pages in Different Directories In reply to
Sounds like you are in a fix! I would drop FrontPage, but that's just me... Tongue

You will pretty much need to have duplicate info, minus the <head> and <body> tags. How many pages are you talking about?


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] Include Pages in Different Directories In reply to
Hummm!!! that is the last thing I want to do to drop FrontPage as my site is too deeply formated to work with FP.. I am trying to get rid of it .. but for now I guess I have to do redundent pages. I have about 30 include page that I need to redo....
I will try to manage until I have a solution to get rid of FP..
Thanks much again...
Mark..
Quote Reply
Re: [Mark2] Include Pages in Different Directories In reply to
if you change:

Code:
$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
Code:
$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, $1)) {
$self->{'inc'}{$1} = join ("", <INC> );
close INC;
$self->{'inc'}{$1};
}
else {
"Can't find file: ${$self}{'ROOT'}/$1";
}

}
#goe;

You should be able to include files from any directory if they aren't found in your template directory.

then if you want to strip the included file of html/head/body tags so the page will validate, you need to add something like:

Code:
$self->{'inc'}{$1} =~ s,^(.*<\s*body[^>]>),,i;
$self->{'inc'}{$1} =~ s,(<\s*\/body[^>].*)$,,i;

somewhere in there two.

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [fuzzy logic] Include Pages in Different Directories In reply to
Thanks Philip for your help... the building of pages works smothly and the includes works very good.. but I have to specify the whole path for each include... (e.g. /home/website/docs/include-files/file-to-include.htm)
I did not use any variable for the paths... not sure if it would be better... ($build_root_somethin...not sure which variable to use)...
But the thing that did not work is the trimming of the html/title/head/body...etc.) ...
is the example you gave me correct!!! I placed it in the "elseif" section but nothing happen..... so i think this one is not working ...
any advice... thanks much..
Mark
Quote Reply
Re: [Mark2] Include Pages in Different Directories In reply to
No, the trimming I didn't have time to figure out at the time. try this:

Code:
elsif (open (INC, $build_include_path . "/" . $1)) {
$self->{'inc'}{$1} = join ("", <INC> );
close INC;
$self->{'inc'}{$1} =~ s,^.*?<body\s*[^>]?>,,si;
$self->{'inc'}{$1} =~ s,<\/body>.*$,,si;
$self->{'inc'}{$1};
}

And in links.cfg, add:

Code:
$build_include_path = '/full/path/to/includes'; #no trailing slash!!!

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [fuzzy logic] Include Pages in Different Directories In reply to
Thanks again Philip,
I've tried the latest changes, however, they did not work... specially the triming... I do not care about the $build_include_path which give me lots of trouble... but the most important was to trim the body/head/...etc tags... which is still not working somehow... but if I remove the tags and put the files outside the templates directory, then they get included... (but no triming...)
thanks again for your help
Mark
Quote Reply
Re: [Mark2] Include Pages in Different Directories In reply to
I don't see why the trimmig isn't working. It worked fine in my test:

Code:
my $html = <<END_OF_HTML;
<html>
<body>
<%include%>
</body>
</html>
END_OF_HTML

$html =~ s{<%include%>}
{
my $tmp = join ("", <DATA>);
$tmp =~ s,^.*?<body\s*[^>]+?>,,si;
$tmp =~ s,<\/body>.*$,,si;
$tmp;
}goe;

print $html;

__DATA__
<html>
<head>
<title>foo</title>
</head>
<body adlkjd kkd>
dfkja dka
adlk dkd;
</body>
</html>

I guess I'm going to have to install Links 2.0 and adding in the mod to figure it out cause that's kind of annoying me now.

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [fuzzy logic] Include Pages in Different Directories In reply to
Yaaa Philip.. iti s still not working correctly some how...
If I include your first code it works (but no triming), but the second code (with the $build_include_path).. did not work at all.. as got lots of issues with the include path variable....
so, maybe I can make a use of your first code.. but it needs the use of triming...
then what would be the full code and changes..
Thanks much again for all your help...
Mark