Gossamer Forum
Home : Products : Links 2.0 : Customization :

The Answer!

Quote Reply
The Answer!
I think I found it. This from a post in 1999 from Elliot. This "mod" was not added to the resource page and so I want to post and make sure this is still good. You can find all of this and more at http://gossamer-threads.com/perl/forum/showflat.pl?ubb=000413:Forum11

<------ Start of Quote --------->

Okay, I figured out a way to link header and footer text files into LINKS web pages. Here is what you do:

1) Insert the following codes into the "links.cfg" file after the SITE TITLE line:

Codes:
---------------------------------------------
sub site_header {
# -----------------------------------
# This is the header sub-routine. It will place a header into your web pages.

my (%patterns) = (
'MSIE' => 'header.txt',
'Mozilla\/4' => 'header.txt',
'Mozilla\/3' => 'header.txt',
'Mozilla\/2.02' => 'header.txt',
'Mozilla\/2' => 'header.txt',
'Mozilla\/1.01' => 'header.txt',
'Mozilla\/1' => 'header.txt',
'other' => 'header.txt'
);

foreach (keys %patterns) {
if ($ENV{'HTTP_USER_AGENT'} =~ /$_/) {
open (INC, "/path/to/$patterns{$_}") or return "Can't find include file: $patterns{$_}";
return join ("", <INC> );
}
}
open (INC, "/path/to/$patterns{'other'}") or return "Can't find include file: $patterns{'other'}";
return join ("", <INC> );
}

sub site_footer {
# -----------------------------------
# This is footer sub-routine. It will place
a footer into your web pages.

my (%patterns) = (
'MSIE' => 'footer.txt',
'Mozilla\/4' => 'footer.txt',
'Mozilla\/3' => 'footer.txt',
'Mozilla\/2.02' => 'footer.txt',
'Mozilla\/2' => 'footer.txt',
'Mozilla\/1.01' => 'footer.txt',
'Mozilla\/1' => 'footer.txt',
'other' => 'footer.txt'
);

foreach (keys %patterns) {
if ($ENV{'HTTP_USER_AGENT'} =~ /$_/) {
open (INC, "/path/to/$patterns{$_}") or return "Can't find include file: $patterns{$_}";
return join ("", <INC> );
}
}
open (INC, "/path/to/$patterns{'other'}") or return "Can't find include file: $patterns{'other'}";
return join ("", <INC> );
}
---------------------------------------------
(Change the /path/to/ to the ABSOLUTE path where your header and footer text files are located.)

2) Insert the following codes into your global settings in your "site_html_template.pl" file:

Codes:
--------------------------------------------
site_header => &site_header,
site_footer => &site_footer,
--------------------------------------------

3) Upload these files to the appropriate directories in your server. Make sure that you also upload the header and footer text files into your server in the directory you specified in the "links.cfg" file.

4) In your template files, insert the following codes in the places where you want to insert your header and footer files:

Code: (for Header)
---------------------------------------------
<%site_header%>
---------------------------------------------

Code: (for Footer)
---------------------------------------------
<%site_footer%>
---------------------------------------------

The advantage of doing this is that you do not have to clean up your codes (by inserting operators, such as \) and that if you want to change the header and footer, you can do this via a text or WYSIWYG editor (Front Page, Claris Home Page, etc.). Also, like my site, if you have linked pages that are not included in the LINKS program, then you can use a header/footer program that will allow text files to be inserted via SSI.

This reduces the time you have to spend cleaning up codes and putting them into the
site_html_template.pl file.

Note: This mod will only work if you have Server Side Includes (SSI) activated on your server. For Apache Servers, make sure that you make your "index" files to be index.shtml. For NT Servers, make sure that you active shtml or shtm files.

Regards,

------------------
Eliot Lee


<--------- End of Quote ----------->

Does this work? Any suggested changes, improvements etc? This is from an old post. I want to make sure this is still good to go.

Thanks,

Jack

Administrator
SoapVoice.com!
Quote Reply
Re: The Answer! In reply to
All that code is not necessary for a simple header and footer.

My site (perlmad.com) uses a header/footer on every page. All I use is:

header => &header,
footer => &footer

(in the globals)

...and then.....

sub header {

my $output = qq| THIS IS MY HEADER |;
return $output;

}

sub footer {

my $output = qq| THIS IS MY FOOTER |;
return $output;

}


Then just put <%header%>, <%footer%> in your templates.

Installations:http://wiredon.net/gt
MODS:http://wiredon.net/gt/download.shtml

Quote Reply
Re: The Answer! In reply to
Yes, but that means when you edit the header or footer files you use on your non-links pages you also have to go edit the header and footer routines above, right? I mean, the way Elliots code is, you can use the header and footer files as they are and have to edit only one copy of each.

Will his code work, do you know? I just want a nice, simple way of maintaining a multi-page site from one header, footer, and menu file and being to incorporate those into the Links templates for easy updating of the site.

Jack

Administrator
SoapVoice.com!
Quote Reply
Re: The Answer! In reply to
 
All you'd need to do is change:

sub header {

my $output = qq| THIS IS MY HEADER |;
return $output;

}


to:

sub header {

my $header = "/PATH/TO/HEADER.TXT";

open(HEADER, "<$header") || &cgierr("Couldn't open $header : $!");
while (<HEADER>) {
$output .= $_;
}
close(HEADER);
return $output;

}


Then you can use the same header file for Links2/Non-Links2 pages.

...and no I have never used Eliots code.


Installations:http://wiredon.net/gt
MODS:http://wiredon.net/gt/download.shtml

Quote Reply
Re: The Answer! In reply to
Uh, oh. I think I have it.

Can it be this easy?


1. I edit site_html_templates:

<----- CODE ------>

sub header {

my $header = "/PATH/TO/HEADER.TXT";

open(HEADER, "<$header") || &cgierr("Couldn't open $header : $!");
while (<HEADER>) {
$output .= $_;
}
close(HEADER);
return $output;
}

<----- End of Code ------>

Do the same subroutine, substituting "footer" for "header".


2. Add two variables to the global list in the same file:

header => &header,
footer => &footer

{no comma at end of last entry}


3. Each template:

%header%

<-- template fields -->

%footer%

Administrator
SoapVoice.com!
Quote Reply
Re: The Answer! In reply to
Yes thats correct except in the templates you put <%header%> and <%footer%> not %header% and %footer%

Installs:http://wiredon.net/gt
FAQ:http://wiredon.net/gt/download.shtml

Quote Reply
Re: The Answer! In reply to
Darn! Didn't work. I don't even get the error couldn't open header.

Here's the global variable list:

# You can put variables here that you would like to use in any
# of your templates.

%globals = (
date => &get_date,
time => &get_time,
db_cgi_url => $db_cgi_url,
build_root_url => $build_root_url,
site_title => $build_site_title,
css => $build_css_url,
banner => '',
header => $header,
footer => $footer
);


Here are the two routines for the $header and $footer:

sub header {
# ---------------------------------------------------------
# This routine includes my header file

my $header = "/home/jdr7181/www/header.txt";

open(HEADER, "<$header>") || &cgierr("Couldn't open $header : $!");
while (<HEADER>) {
$output .= $_;
}
close(HEADER);
return $output;
}


sub footer {
# -------------------------------------------------------
# This routine includes my footer file

my $footer = "/home/jdr7181/www/footer.txt";

open(FOOTER, "<$footer>") || &cgierr("Couldn't open $footer : $!");
while (<FOOTER>) {
$output .= $_;
}
close(FOOTER);
return $output;
}


At the top of the modify.html template I added:

<%header%>


What's wrong? Any ideas? Would it matter if I tried relative paths to the two txt files?

Jack


Administrator
SoapVoice.com!
Quote Reply
Re: The Answer! In reply to
Hey Paul

Can you take a look at this post of mine on headers and footers

http://gossamer-threads.com/...=&part=&vc=1

I'd appriciate any comments you have on what I'm doing.

PS - thanks for showing me EditPlus - I still use 1st Page or CoffeeCup for the heavy duty stuff but it is nice for quick changes....



Gene
Quote Reply
Re: The Answer! In reply to
You didn't follow my instructions properly.

I said

header => &header,
footer => &footer

not

header => $header,
footer => $footer

Installs:http://wiredon.net/gt
FAQ:http://wiredon.net/gt/download.shtml

Quote Reply
Re: The Answer! In reply to
why don't you just use the include tag (<%include header.txt%>)?

--Drew

Code:
s;[\d\$&(\^)];;g+s;\.; ;g+s;(.)(..);$2$1;g+print,if$_='&61k4I.)l678il.edn7(K2e^ny$';
Quote Reply
Re: The Answer! In reply to
Because the include tag is SSI, which I understand cannot be used in cgi-generated pages. Though, some UNIX systems let you play with a .htaccess file that will allow you to include SSI tags in such pages.

Isn't this right?

Personally, I am still having some problems. I corrected the mistake in my variable declaration that Paul Wilson so graciously pointed out and it is sort-of, almost, kind of working.

The problem is the header at the top of the screen is fine, then at the bottom of the page it puts both the header and the footer, one on top of the other.

I have double checked everything that I know of. There is only one <%header%> and one <%footer%> on the template. I checked the footer.txt file and it does not contain the info from the header.txt file. I checked the two subroutines and they both look fine. What have I overlooked? You can go to http://www.soapvoice.com/cgi-bin/links/modify.cgi and see what I am talking about. I will continue to try to resolve this, but if anyone has any idea what I messed up I would really appreciate the help.

Thanks,

Jack

Administrator
SoapVoice.com!
Quote Reply
Re: The Answer! In reply to
In Reply To:
Because the include tag is SSI, which I understand cannot be used in cgi-generated pages. Though, some UNIX systems let you play with a .htaccess file that will allow you to include SSI tags in such pages.

Isn't this right?
<%include header.txt%> IS NOT SSI! It has nothing to do with SSI. The tag is parsed through Template.pl, which is part of your Links2.0 package.

Quote Reply
Re: The Answer! In reply to
Ok. So the header and footer.txt files just need to be in the same directory? If I go with the include tag, how does it know where the header and footer files are?

Jack

Administrator
SoapVoice.com!
Quote Reply
Re: The Answer! In reply to
In Reply To:
Ok. So the header and footer.txt files just need to be in the same directory? If I go with the include tag, how does it know where the header and footer files are?
The header (or any file with any extention) reside in you template directory for the <%include filename%> tag to find it or if I'm not mistaken you can give it a path/to/filename and park it anywhere.

Quote Reply
Re: The Answer! In reply to
The <%include filename%> tag is only available with the Enhanced Template Mod. If you are using this, rather than editing all the other files, then all you need to do is upload the include files to the /admin/templates/ folder, and use <%include file.txt%> (or whatever) in your templates.

Andy

webmaster@ace-installer.com
http://www.ace-installer.com
Quote Reply
Re: The Answer! In reply to
No you can't park it anywhere it has to be in the templates directory (as far as I know).

Only Links SQL supports <%include /path/to/header.txt%>

Installs:http://wiredon.net/gt
FAQ:http://www.perlmad.com

Quote Reply
Re: The Answer! In reply to
In Reply To:
rather than editing all the other files, then all you need to do is upload the include files to the /admin/templates/ folder, and use <%include file.txt%> (or whatever) in your templates.
You mean uploading the include files, editing the templates and replacing the parse sub in Template.pm with the enhanced one?...LOL I think my way is shorter.

Installs:http://wiredon.net/gt
FAQ:http://www.perlmad.com