Gossamer Forum
Home : Products : Links 2.0 : Customization :

Allow "Include a file in Templates" to be in any category/directory you want- MOD

Quote Reply
Allow "Include a file in Templates" to be in any category/directory you want- MOD
This topic is both a question and a learning statement that all started when I wanted to include a file in my template (thanks to the help of bobsie, pugdog, and others). First I installed the if-then-include-file mod for Template.pm. (it's somewhere in this forum I will find it and put it here). The if-then mod worked all fine and dandy, but it has limitations (for what I needed) in what directory the "include" file is pulled from.

However, as my project developed (using my shoot from the hip style of programming) I eventually realized that I had to go one step further. I had to be able to not only tell Template.pm what file I wanted to include; I also, had to pass to Template.pm the directory that the "included" file was in.

Then I got a brain storm and I thought something like this would do the trick.
____________________________________________
<%include <%build_root_url%>header.htm%>
____________________________________________


In hopes that I might get lucky and Template.pm sub parse routine would pass both build_root_url and header.htm to the open statement there.

That did not work (got a tag error in template.pm).

It was a cheap and lazy trick anyway. So I came up with something else. I decided to do my own thing. I put in the Detail.html template the following:

<%include UseMyIncludes%>

Then I added/modified the "include" mod/code in Template.pm so the "UseMyIncludes" would trigger a switch (switches are bad and a lazy way to program , but...) here is my code for this:

[Warning: do not try this at home Smile This is only a cut/paste of test code I am currently using and does not include the entire mod! Smile]

___________Code In Template.pm if-then Include Mod.__________
____________________________________________

$includeFILE = $1;#this is where the actual included file name will come into when it is passed.
$ROOTdir = ${$self}{'ROOT'};#this is where the included files directory will come into.
if ($includeFILE eq "UseMyIncludes")
{
$includeFILE = "advert.htm";#this is hard coded now with hopes to make it a passed variable later.
$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-->";
}
}
____________ cut of the parts for discussion._________-
____________________________________________


So I tried to pass the variables I needed to do this. I could not figure how to capture the build_root_path or build_root_url so I came up with attempting to pass and build it myself. By debugging, I worked my way back from Template.pm, dbutil.pl, site_html_templates.pl, nph-build.cgi and found (in that order) I had to start my pass of the new variables.

My current perl knowledge did not allow me to figure how to get some of this data even if it was already being passed. I later learned (see credits above) that most of what I needed was in %rec but can not figure how to get to it. By using the print (); statement as a debug tool in Template.pm (sub parse). (see Related Topics/Threads below if you want more on this).

The additions I currently have in use do work. However, I later learned that though the shift function works (in use now)it both catches the variable contents and it also literally shifts the data passed. So I should find another method that will not effect the current working of things for other calls using the routine elsewhere or other code afterwards in the routine. (thanks pugdog and bobsie for help on this. Again, see http://www.gossamer-threads.com/scripts/forum/resources/Forum3/HTML/002618.html if you want more on this subject)

I think that about raps up the explaination.

Bobsie, this also might explain that other thread you asked a question on. (I will post that thread here if I can ever find it... about the <%include <%somethinghere%>header.txt%> I think) Smile

Will FILL OTHERS NEEDS TOO?...
______________________________
After using what I currenly have I think others might find the mod very usefull because it also allows you to use links2 to build other file (index.html, home.htm, classifieds.htm or what ever) in the same categories/directories where you can later have a final links2 pick them ALL up into one web page. It works really cool

If you need more details on all this let me know. I also plan on increasing this mod-of-a-mod as I came up with a few other uses/ideas as this progressed with some help from my friends

________________
RELATED TOPICS/THREADS:
________________
http://www.gossamer-threads.com/scripts/forum/resources/Forum3/HTML/002618.html

Thanks
TimRyan



[This message has been edited by timryan (edited August 07, 1999).]

[This message has been edited by timryan (edited August 07, 1999).]
Quote Reply
Re: Allow "Include a file in Templates" to be in any category/directory you want- MOD In reply to
 
Quote:
Then I got a brain storm and I thought something like this would do the trick.
____________________________________________
<%include <%build_root_url%>header.htm%>
____________________________________________

I think the problem you had with that is that it is not written correctly. It should have been:

Quote:
<%include <%build_root_url%>/header.htm%>

$build_root_url is not configured with an ending slash, so you need to put one on it before appending a filename to it. I am not sure that you can embed another linkstag like that anyway. I believe the syntax for the <%include%> tag is:

Quote:
<%include filename%>

so the call should be:

Quote:
<%include /path/to/your/root/header.htm%>

Since you have progressed beyond that, this is probably a moot point. I just thought I would mention it.
Quote Reply
Re: Allow "Include a file in Templates" to be in any category/directory you want- MOD In reply to
Thanks and I agree on the format...
quote:
--------------------------------------------------------------------------------

<%include /path/to/your/root/header.htm%>

--------------------------------------------------------------------------------

as being the correct format but that takes away from my original idea/need of makeing the path a variable.
TimRyan


[This message has been edited by timryan (edited August 07, 1999).]