Gossamer Forum
Home : Products : Links 2.0 : Discussions :

Headers & Footers

Quote Reply
Headers & Footers
Okay, I have created a Header and Footer directory that is reflected in my links.cfg. I have placed a file called header.html in the header directory and one called footer.html in the footer directory. Now how do I get the contents of the header.html and footer.html files to show up in all of my pages?
Quote Reply
Re: Headers & Footers In reply to
You don't because that is not what those directories are for. They will contain the files named in the header and footer fields of the category record and will pertain only to the category for which they are specified.

To use a header and footer file like you want so that it appears on all pages, you need to go into the Globals section of either site_html.pl or site_html_templates.pl and create two variables:

$site_header = qq~Your header html code here~;
$site_footer = qq~Your footer html code here~;

If you are not using templates, $site_header and $site_footer can be used by any of the subroutines in site_html.pl to display the header and footer.

If you are using templates, you need to add two lines to the %globals variable list, like so:

site_header => $site_header,
site_footer => $site_footer,

Then you can use <%site_header%> and <%site_footer%> in any of the template files to display your header and footer.

I hope this helps.

[This message has been edited by Bobsie (edited May 08, 1999).]
Quote Reply
Re: Headers & Footers In reply to
How about using separate files for header and footer? What are the appropriate codes that will make header and footer files work on all template pages?

Currently, I am using a SSI perl script for header/footer files. But it would be nice to have this integrated within the LINKS program.

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: Headers & Footers In reply to
Eliot,

Did you read my reply above? That is exactly the instructions I gave. A header and footer can be globally defined and used with any template file. If there are not template files, they can still be used in the non-template subroutines of site_html_templates.pl. That's why they are called "globally defined."

You don't need to use SSI for headers/footers.
Quote Reply
Re: Headers & Footers In reply to
Yes, I read your posting. However, what I was looking for was a way to create a separate footer and header file rather than inserting HTML codes into the site_html_template.pl file. The codes you gave show that you have to enter codes into the site_html_template.pl:

------------------------------------------
$site_header = qq~Your header html code here~;
$site_footer = qq~Your footer html code here~;
------------------------------------------

What I was looking for was an easier way than copying and pasting new codes into the site_html_template.pl when I want to change the header and footer. I suppose your solution will work just fine.




------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: Headers & Footers In reply to
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
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us

[This message has been edited by Eliot (edited May 21, 1999).]

[This message has been edited by Eliot (edited May 21, 1999).]

[This message has been edited by Eliot (edited May 22, 1999).]

[This message has been edited by Eliot (edited May 22, 1999).]

[This message has been edited by Eliot (edited May 22, 1999).]
Quote Reply
Re: Headers & Footers In reply to
Eliot,

Nice write-up and, from what I see, well thought out. You might want to consider adding this to the Gassamer Threads Resource Center as a mod.

I only have one comment concerning using links.cfg versus using site_html.pl or site_html_templates.pl to do this. The links.cfg file is used primarily for configuration settings. The only exceptions are the date subroutines which need to be accessible to all the scripts and links.cfg is always required by all the Links scripts, unlike site_html.pl or site_html_templates.pl. That is why there is a Global section at the top of site_html.pl or site_html_templates.pl and contains the comment:

Quote:
# You can put variables here that you would like to use throughout
# the site.

That comment is not just referring to the %globals variable but is for any global variables you may want to add and reference in the %global variable.

Anyway, it works well either way and I congratulate you on a job well done.
Quote Reply
Re: Headers & Footers In reply to
I'm still just playing with links II, but wanted to use my standard header file. Rather than replicating it within a LINKS file (yet another place to maintain code), I accomplished it by applying the mod to allow server side includes. Then, in the template files I just put an include to my standard header file.

You do need to play with the .htaccess to have the server parse a .html file for ssi's if you're on a Unix box.

If you want the header file to be smart, to change it's look based upon the calling page, then you could just write a little cgi that creates the appropriate header file based upon what page called it.

Anyway, worked for me, it's simple, and allows me to have all my header and footer files in one directory. That directory serves ALL of the headers for all of the applications at my site. Simplifies maintenance for my simple ,and aging, mind.

-Robert
Quote Reply
Re: Headers & Footers In reply to
Bobsie,

Thanks for the compliments. I am glad that this mod is useful. However, I cannot take all the credit. The mod is based on input from "jdulberg" and you. If I do submit this mod, I would make it clear that you and jdulberg added pieces to it.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: Headers & Footers In reply to
I've been trying make this mod on my program and I can't quite get it to work. I copy and pasted the code provided to avoid typing errors. I've tried putting the code in my Link.cfg and the site_html_templates.htm, but no matter where I put it I recieve the following error code...

Error including libraries: Can't modify concatenation in scalar assignment at /data1/hypermart.net/pscards/cgi-bin/links/admin/site_html_templates.pl line 88, near ");"

Make sure they exist, permissions are set properly, and paths are set correctly.

I placed the header and footer files into the templates directory, specified that directory and chmod'ed them. Can anyone help?

Quote Reply
Re: Headers & Footers In reply to
Could you not just use the "Include header.txt" mod (see that thread)... sorry I forget where it is. But would that not server the same purpose and just include the header.txt into the templates directory where this mod looks for it. I have also use another recommendation found in a thread (forum) that uses the <%header%> global. That also works fine. Not sure what the dif between them are. But I have tried both and they seem to work fine. Why add all that code? This is not criticism on your code Eliote, but rather an educational question.
Tim
Quote Reply
Re: Headers & Footers In reply to
Bobsie - You suggested that the code for defining the header.txt variable not be included in links.cfg. Where would be a better place to include it?
I have taken Elliot's code and used it as follows, but it isn't working. I don't get an error message, it just doesn't include the file. I think my mistake may be with the incorrect use of % or $.

In site_html_templates.pl - before the %globals section
Quote:
sub whats_new {
# -----------------------------------
# This is the what_new sub-routine. It will place the whats_new.txt into your web pages.

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

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

In the %globals section I have put
Quote:
whats_new => $whats_new,

Then in my template files, I have put <%whats_new%>

Elliot - when you said SSI needed to be activated, we are using NT IIS, and Frontpage and other "normal" includes work, however I am not using .shtml as my file extension.

Also, can the text files include <body> tags or should those be remmed from the text file (if you use frontpage to modify the file, it will put in the <body> and <html> tags.)

Any help would be greatly appreciated.

[This message has been edited by lunaria (edited July 10, 1999).]
Quote Reply
Re: Headers & Footers In reply to
I put all my global variables at the top of site_html_templates.pl, just above the %globals array. If they are truly global (not just used withing site_html_templates.pl subroutines), then I also stick the in the %globals array.

I try to leave links.cfg alone except for configuration changes.
Quote Reply
Re: Headers & Footers In reply to
Lunaria

This mod functions under SSI with file extensions of .shtml or .shtm. Try changing your file extensions to .shtml in the links.cfg file. Also, you may have to add .shtm, .shtml in your File Mapping Option in IIS. Set the files similar to .htm and .html.

TimRyan

This mod is great for maintaining consistancy accross web pages that may not be used in LINKS. For example, I have about thirty web pages that I do not want to include as templates or into the LINKS program. Having the option of inserting header and footer files is A LOT easier than editing multiple files!!

Also, with the "Include Header" option that comes with Links, you have to copy codes and paste them into the site_html_templates.pl file. Whenever you need to change header and footer files, you have to go back into the site_html_template.pl file. The reason of adding ALL THAT CODE is that my mod also allows you to create different footer and header files for different operating systems!!!

PlanetSheldon

Try putting the header and footer sub-routines in your links.cfg file. Follow the directions as written!

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us

[This message has been edited by Eliot (edited July 11, 1999).]
Quote Reply
Re: Headers & Footers In reply to
Lunaria,

Hi again...I am experimenting with ASP server side programming using Perl rather than Visual Basic. I may have a fix for your problem utilizing ASP sometime.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us