Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Include Files Outside Templates Directory

Quote Reply
Include Files Outside Templates Directory
Is it possible to include files outside the 'templates' directory?

I do not mean the <%header%> or <%footer%>, I know how to include them, but would like to have a file that can be incorporated into all my pages that links builds PLUS the other pages that I develop myself outside of links.

I would like to use SSI on my own pages, but am aware there is a problem with SSI with cgi generated pages, so rather than keep two sets of files, I want to develop one file and call it as follows:-

1. All Links pages
<%include /path/to/abc.txt%>

2. Other pages (non 'links')

< SSI include directive /path/to/abc.txt> (I can't seem to use the example I wanted to here for obvious reasons!).

Is this possible OR would I need to change the Templates Directory. (I cannot use SSI to call files located under the CGI Bin Directory).

Thanks in advance,

Regards,


Clint

--------------------------
http://www.AffiliatesDirectory.com - Affiliate Programs Directory
Quote Reply
Re: Include Files Outside Templates Directory In reply to
What you can do is the following:

1) Add the following variables in the Links.pm file:

Code:

# Path where included files are located
# NO Trailing Slash
$LINKS{db_files_path} = "/absolute/path/to";

# Included file name
$LINKS{includefile} = "include.txt";


2) Then add the following sub in your HTML_Templates.pm OR Links.pm file:

Code:

sub include_file {
# -----------------------------------
# This is a list of patterns to the appropriate shtml page to load.

open (INC, "$LINKS{db_files_path}/$LINKS{includefile}") or return "Can't find
include file: $LINKS{db_file_path}/$LINKS{includefile}";
return join ("", <INC> );
}


3) Then in the %GLOBALS hash section of the HTML_Templates.pm file, add the following global tag configuration:

Code:

includefile = > \&include_file,


NOTE: If you put this at the end of the list, you do not need a comma.

4) Then in all your template files, you can use:

Code:

<%includefile%>


Of course, you can change the names of the variables and sub to fit what you need.

Good luck!

Regards,

Eliot Lee

Quote Reply
Re: Include Files Outside Templates Directory In reply to
Great Idea! Actually with a couple of changes I imagine I could point to the 'directory' of where the includes were, thus enabling me to have a number of different includes.

Thanks very much.

Regards,

Clint.

--------------------------
http://www.AffiliatesDirectory.com - Affiliate Programs Directory
Quote Reply
Re: Include Files Outside Templates Directory In reply to
Yes...you could. Perl is a very flexible language and the possibilities are endless...although with SQL...it is a bit more challenging. Wink

Regards,

Eliot Lee