Gossamer Forum
Home : Products : Links 2.0 : Customization :

diff templates: search.cgi?template1

Quote Reply
diff templates: search.cgi?template1
Can someone please help me on this. I'd like all the cgi scripts such as search.cgi, add.cgi, mylinks.cgi etc. to look at different directories for their templates. So if I go to search.cgi?templat1 it will grab the templates from the designated directory.

What's a good way to do this with the least amount of work, have different links.cfg files loaded in the scipts or something?

Thanks a bunch
Shane

[This message has been edited by shane1800 (edited January 12, 2000).]
Quote Reply
Re: diff templates: search.cgi?template1 In reply to
You just want to use a different directory for template files in the *.cgi scripts????

Why?

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
http://www.anthrotech.com
Be sure to visit the Resource Center for FAQ's, Modifications and Extra Goodies!!
----------------------





Quote Reply
Re: diff templates: search.cgi?template1 In reply to
I want to give other web sites my directory with the pages customized to look like their site. Kind of a co-branding idea. So if I can call cgi scripts and indicate the templates I won't need a seperate cgi script for each site directory. Does this sound right, is there an easier way?


Shane
Quote Reply
Re: diff templates: search.cgi?template1 In reply to
Well, here is a possible solution:

1) Add the following sub-routine in your db_utils.pl file:

Code:
sub load_search_templates {
#-------------------------------------------
# Loads and parses a template. Expects to find as input a
# template file name, and a hash ref and optionally template text.
# If text is defined, then no file is loaded, but rather the template
# is taken from $text.
#
my ($tpl, $vars, $string) = @_;
(ref $vars eq 'HASH') or &cgierr ("Not a hash ref: $vars in load_template!")
;

if (!defined $db_template) {
require "$db_lib_path/Template.pm";
$db_template = new Template ( { ROOT => $db_template_search_path, CHECK => 0 }
);
}
$db_template->clear_vars;
$db_template->load_template ($tpl, $string) or &cgierr ("Can't load template
. Reason: $Template::error");
$db_template->load_vars ($vars) or &cgierr ("Can't load variable
s. Reason: $Template::error");
return $db_template->parse ($tpl) or &cgierr ("Can't parse templat
e. Reason: $Template::error");
}

2) Add the following variable in the links.cfg file:

Code:
$db_template_search_path = "$db_script_path/searchtemplates";

3) Create a directory called searchtemplates.

4) Then in your site_html_template.pl file, change the following sub-routine calls in ALL the search template sub-routines:

Code:
&load_templates

to the following:

Code:
&load_search_templates

5) Then upload the various template files in this directory.

6) Then in your admin_html.pl template file, add the following codes:

Code:
sub html_edit_search_template {
# --------------------------------------------------------
# Lets the user edit his templates.
#
my $message = shift;
my $templates = &get_template_list($in{'edit_tpl'});
my $text = '';
if ($in{'edit_tpl'} =~ /^[\w\d_\-]+\.[\w\d_\-]+$/) {
open (TPL, "<$db_template_search_path/$in{'edit_tpl'}") or &cgierr ("Can't load template: $db_template_path/$in{'edit_tpl'}. Reason: $!");
$text = join "", <TPL>;
close TPL;
$text =~ s,</textarea>,</text-area>,ig;
}
my $save_as = $in{'edit_tpl'};

&html_print_headers();
print qq|
<html>
<head>
<title>$html_title: Edit Templates.</title>
</head>

<body bgcolor="#FFFFFF">
<form action="$db_script_url" METHOD="POST">
<input type=hidden name="db" value="$in{'db'}">

<table border=1 bgcolor="#FFFFFF" cellpadding=5 cellspacing=3 width=500 valign=top>
<tr><td colspan=2 bgcolor="navy">
<FONT FACE="MS Sans Serif, arial,helvetica" size=1 COLOR="#FFFFFF">
<b>$html_title: Edit Templates</b>
</td></tr>
</table>

<p><$font color=red><b>$message</b></font></p>
|; if ($in{'edit_tpl'}) { print qq~<p><$font><b><a href="$db_script_url&html_template_help=1&template=$in{'edit_tpl'}">Template Help and Codes you can use!</a></b></font></p>~; } print qq|
<p><$font>Available Search Templates: $templates <input type=submit name="html_edit_search_template" value="Edit!">
<p><textarea name=tpl rows=40 cols=60>$text</textarea>
<p><$font>Save as: <input name="save_tpl" value="$save_as"></font>
<p><INPUT TYPE="SUBMIT" NAME="save_search_template" VALUE="Save Template"> <INPUT TYPE="RESET" VALUE="Reset Form"></p>
</body>
</html>
|;
}

That should do it...Let me know if I missed something or if you get error messages.

The next tricky step will do that template argument in the search.cgi script.

But I would prefer you make these changes before we proceed.

Hope this helps.

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
http://www.anthrotech.com
Be sure to visit the Resource Center for FAQ's, Modifications and Extra Goodies!!
----------------------





Quote Reply
Re: diff templates: search.cgi?template1 In reply to
Did all the changes Eliot and everything works fine! What's next?

P.S. can I go through and change &load_template to &load_search_templates for the modify.cgi, add.cgi etc.

I want all of the scripts to load the special templates.


Thanks
Shane
Quote Reply
Re: diff templates: search.cgi?template1 In reply to
Sure...

For matter of organizing, you might want to change sub load_search_templates to something like sub load_script_templates.

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
Be sure to visit the Resource Center for FAQ's, Modifications and Extra Goodies!!
----------------------







[This message has been edited by Eliot (edited January 22, 2000).]