Thanks pugdog, that was good! And you are right it is in the "load_template" call.. I have been working on a Links2 project that uses 2 copies of Links2 (one for resource templates and another for a mod I am doing for a free classifieds/ads) to merge the 2 into one in the details page. I want to pass some fields (see above).. I will put >>>>> on code lines I think need to be changed for passing the strings/variables .
...Get a big cup of java for this one
____________________________
The calling code starts at...
____________________________
___________site_html_templates.pl_________________
sub site_html_detailed {
# --------------------------------------------------------
# This routine will build a single page per link. It's only
# really useful if you have a long review for each link --
# or more information then can be displayed in a summary.
#
my %rec = @_;
>>>>>> return &load_template ('detailed.html', {
total => $total,
grand_total => $grand_total,
title_linked => $title_linked,
%rec,
%globals
} );
}
____________________________
Then from there goes to...
____________________________
_____________db_utils.pl_______________
sub load_template {
# --------------------------------------------------------
# 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_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 variables. Reason: $Template::error");
>>>>>> return $db_template->parse ($tpl) or &cgierr ("Can't parse template. Reason: $Template::error");
}
____________________________
and from there goes to finally Routine in...
____________________________
__________Template.pm __________________
sub parse {
# ---------------------------------------------------------------
# Parses a template.
#
my $self = shift;
my $template = shift;
>>>>>> (will add code to pickup the passed variables to be used in this routine.)
my $begin = $self->{'begin'} | | quotemeta('<%');
my $end = $self->{'end'} | | quotemeta('%>');
---- cut here for length....
____________________________
End of the way these routines originally looke before my changes/test/debugs..
==================================
NOW, for my proposed changes below... I have used print statments to do my debuging on the variables so I think I am close cause most seems to work. My Biggest problem is that the books did not who me where to put the code to start the pass in sub site_html_detailed {... so I had to guess at this..
________________________________
return &load_template ('detailed.html', {
total => $total,
grand_total => $grand_total,
title_linked => $title_linked,
%rec,
%globals
# });
},$nullx, $Category, $ID );
__________________________
Not sure if this is the right place to put the 3 strings I want to pass... $nullx, $Category, $ID. It works but I have never seen this in the books.
I cannot remember why I had to put in the $nullx variable to get things to shift right.
Also, I sure would like to know how to print out those variables above so I can better see what is being passed and where. So far I can print out 'detailed.html', $Category, and $ID. BUT, I cannot see what happens to the middle items (not that I need them. I just would feel more comfortable knowing where they went on the pass to the call.).
__________________________
sub load_template {.........
my ($tpl, $vars, $string, $string2, $string3) = @_;
__________________________
sub parse {.......
my $self = shift;
my $template = shift;
#mystuff these below variables 7-30-99 that where needed to read another sidebar file to include in detailed page
my $build_root_path = shift;
my $Category = shift;
my $ID = shift;
my $build_extension = shift;
#mystuff these above variables 7-30-99 that where needed to read another sidebar file to include in detailed page
__________________________
So far these seem to work BUT... there are so many calls to these routines from module to module I want to be sure as I can on this.
Thanks (I did not want to right a book on this
so I hope I did not leave out to much. To save space, I will not bother to show my code for what I finally do with the variables. (oh, what the hay... I went this far, I might as well tell you why
Also, for some other info On what I have been trying to do see the following threads..
1. http://www.gossamer-threads.com/scripts/forum/resources/Forum11/HTML/000875.html
2. http://www.gossamer-threads.com/scripts/forum/resources/Forum3/HTML/002512.html
3. http://www.gossamer-threads.com/scripts/forum/resources/Forum3/HTML/002542.html
___________________________________
NOW for the WHY of it all
___________________________________
I have gone this far to show what I have done so I might as well show why I have done it..
Here is part of the routine in :
Template.pm at ... sub parse {
___ cut...
# Parse includes, do this first so that the includes can include
# template tags.
my $includeFILE = "";#lets make an include directory = a subdirectory of /templates
my $ROOTdir = "";#lets make an include directory = a subdirectory of /templates
$temp =~ s#$begin\s*include\s*(.+?)\s*$end#
if (exists $self->{'inc'}{$1}) { $self->{'inc'}{$1}; }
else {
$includeFILE = $1;
$ROOTdir = ${$self}{'ROOT'};
if ($includeFILE eq "UseMyIncludes")
{
$includeFILE = "advert.htm";
$ROOTdir = "$build_root_path/$Category";
}
if (open (INC, "$ROOTdir/$includeFILE")) {
$self->{'inc'}{$1} = join ("", <INC> );
close INC;
$self->{'inc'}{$1};
}
else {
"*Open AdFile Error*<--Can't find file:<br>$ROOTdir<br>/$includeFILE-->";
}
____End of cut______________________________
Now all I do is put <%include UseMyIncludes%>
in my Resource templates as needed and the above routines will allow me to "include" my "advert.htm" files created from my second Links2 Classifieds setup. (I use the If-Include Mod from resource center in Template.pm)
Understand that both Resource/Detail (index.html) pages and Classifieds (advert.htm) are in the same category directories and merged into one final web page by using this routine.
I run 2 builds. One for Classifieds entered online for the day and the second build is for Resources/Articles validated for that day. In that order so the Classifieds (advert.htm) are sucked into the Resources/Articles during that build.
Yes, I tried to figure a way to use the current <%include ?????.???%> mod but I could not. Because, it seemed to me that to acomplish this merge would require a sub/include within the include. So I ended up with this technique. Also, I wanted to try and utilize the current mods and calls already in Links2/Templates.
I would be glad to here from anyone with any other ideas that might make this work easier.
I will clean this all up a bit after I figure all this out. Later on I would even like to pass the "advert.htm" in as a variable also from links.cfg.
TimRyan
[This message has been edited by TimRyan99 (edited August 04, 1999).]