Gossamer Forum
Home : Products : Gossamer Links : Discussions :

<%include %> insert not working

Quote Reply
<%include %> insert not working
I create new column in ctegory column and name it "partner"
So in my template directory i have file partner.txt.
I add tag <%include partner.txt%> to category description(to partner form)
o when I build my pages,its wount include my file,its just print <%include partner.txt%> tag on a page.

How to fix it?
help please.

Quote Reply
Re: <%include %> insert not working In reply to
that won't work.

(obviously).

What you could do, is use the "header" and "footer" field in the Category record, if you are not using them already.

Anything put in those fields is stuffed into the tag <%header%> and <%footer%>

_DON'T_ confuse this with using <%include header.txt%> <--- that means, when the template is being parsed, look for the header.txt file, parse it, and include it at that point.

<%header%> means simply include the stuff that is in the <%header%> tag.

The <%header%> tag is created _BEFORE_ the template is parsed. In the routine that reads the category record, those two fields have the special property of if they are LESS THAN 20 characters long, the name is assumed to be a file name, and the command "include .../admin/headers|footers/filename.txt" is executed.

Here is the code:

# Get the header and footer from file if it exists, otherwise assume it is html.
if ($display{header} && (length($display{header}) < 20) && ($display{header} !~ /\s+/) && (-e "$CFG->{admin_root_path}/headers/$display{header}")) {
open (HEAD, "<$CFG->{admin_root_path}/headers/$display{header}") or die "Unable to open header file: $CFG->{admin_root_path}/headers/$display{header}. Reason: $!";
$display{header} = join "", <HEAD>;
close HEAD;
}
if ($display{footer} && (length($display{footer}) < 20) && ($display{footer} !~ /\s+/) && (-e "$CFG->{admin_root_path}/footers/$display{footer}")) {
open (FOOT, "<$CFG->{admin_root_path}/footers/$display{footer}") or die "Unable to open footer file: $CFG->{admin_root_path}/footers/$display{footer}. Reason: $!";
$display{footer} = join "", <FOOT>;
close FOOT;
}

This is probably the easiest way to do what you want to do. Just forget the name <%header%> and <%footer%>, and think of them as "include file #1 and #2".

If you are using that field, and you want to add a separate file, the best way is to edit the Build.pm file, where you see the lines above, and add:


$display{partner} = $category->{'partner'}; ## this puts your new column in the output hash.
if ($display{partner} && (length($display{partner}) < 20) && ($display{partner} !~ /\s+/) && (-e "$CFG->{admin_root_path}/partners/$display{partner}")) {
open (FOOT, "<$CFG->{admin_root_path}/partners/$display{partner}") or die "Unable to open partner file: $CFG->{admin_root_path}/partners/$display{partner}. Reason: $!";
$display{partner} = join "", <FOOT>;
close FOOT;
}

Don't forget to create a subdirectory in your 'admin' subdirectory called 'partners'.

You'd put your text file in there.

You'd have to make this change to any future links release, but it works.

PUGDOGŪ Enterprises, Inc.
FAQ:http://LinkSQL.com/FAQ
Forum:http://LinkSQL.com/forum
Quote Reply
Re: <%include %> insert not working In reply to
Thanks for your fast answer.
Ok,I create partner dir in my admin directory,then post 1.txt file there.
So then I add
$display{partner} = $category->{'partner'}; ## this puts your new column in the output hash.
if ($display{partner} && (length($display{partner}) < 20) && ($display{partner} !~ /\s+/) && (-e "$CFG->{admin_root_path}/partners/$display{partner}")) {
open (FOOT, "<$CFG->{admin_root_path}/partners/$display{partner}") or die "Unable to open partner file: $CFG->{admin_root_path}/partners/$display{partner}. Reason: $!";
$display{partner} = join "", <FOOT>;
close FOOT;
}

after
if ($display{footer} && (length($display{footer}) < 20) && ($display{footer} !~ /\s+/) && (-e "$CFG->{admin_root_path}/footers/$display{footer}")) {
open (FOOT, "<$CFG->{admin_root_path}/footers/$display{footer}") or die "Unable to open footer file: $CFG->{admin_root_path}/footers/$display{footer}. Reason: $!";
$display{footer} = join "", <FOOT>;
close FOOT;
}

And add <%include 1.txt%> to parnter field in category description menu.

but it`s wount include file and now.

where is bug?

Quote Reply
Re: <%include %> insert not working In reply to
Just put 1.txt in the partner field of the category table. It's automatically parsed, and stuffed into the <%partner%> tag.

PUGDOGŪ Enterprises, Inc.
FAQ:http://LinkSQL.com/FAQ
Forum:http://LinkSQL.com/forum
Quote Reply
Re: <%include %> insert not working In reply to
its working now!
thanks for your help!


Quote Reply
Re: [pugdog] <%include %> insert not working In reply to
I would like to be able to include a different banner HTML code in certain categories. For that I have created a new category column called "banner". I have then also created a directory "banners" in the admin directory and put a tiny HTML test file in it called test.html.

I then made the following (highlighted) additions to Build.pm

black text is what was there before, orange is what I added... :



# Get our output vars.
my %display;
$display{category_id} = $category->{'ID'};
$display{category_name} = $category->{'Full_Name'};
$display{header} = $category->{'Header'};
$display{footer} = $category->{'Footer'};
$display{banner} = $category->{'banner'};
$display{meta_name} = $category->{'Meta_Description'};
$display{meta_keywords} = $category->{'Meta_Keywords'};
$display{description} = $category->{'Description'};
$display{random} = int rand (10000);
$display{random1} = int rand (10000);
$display{random2} = int rand (10000);
$display{random3} = int rand (10000);


.... and then elsewhere :



# Get the header and footer from file if it exists, otherwise assume it is html.
if ($display{header} && (length($display{header}) < 20) && ($display{header} !~ /\s+/) && (-e "$CFG->{admin_root_path}/headers/$
display{header}")) {
open (HEAD, "<$CFG->{admin_root_path}/headers/$display{header}") or die "Unable to open header file: $CFG->{admin_root_path}
/headers/$display{header}. Reason: $!";
$display{header} = join "", <HEAD>;
close HEAD;
}

if ($display{footer} && (length($display{footer}) < 20) && ($display{footer} !~ /\s+/) && (-e "$CFG->{admin_root_path}/footers/$
display{footer}")) {
open (FOOT, "<$CFG->{admin_root_path}/footers/$display{footer}") or die "Unable to open footer file: $CFG->{admin_root_path}
/footers/$display{footer}. Reason: $!";
$display{footer} = join "", <FOOT>;
close FOOT;
}


# $display{banner} = $category->{'banner'}; ## this puts your new column in the output hash.

if ($display{banner}
&& (length($display{banner}) < 20)
&& ($display{banner} !~ /\s+/)
&& (-e "$CFG->{admin_root_path}/banners/$display{banner}"))
{
open (FOOT, "<$CFG->{admin_root_path}/banners/$display{banner}")
or die "Unable to open banner file: $CFG->{admin_root_path}/banners/$display{banner}. Reason: $!";


$display{banner} = join "", <FOOT>;

close FOOT;
}



While working on it, to test everything, I also created a directory "footers" in admin, same place I created "banners" directory.

I then also created a sample file for footers, basically doing the same thing that I did with the new "banner" and banners directory.

<%footer%> and <%banner%> were added in the template...

(footer is all lowercase here but it works even though it was defined as "Footer"...?)



Here is the weird thing, though the code seems identical (the original "footer" code and the new "banner" code), the footer does kick in and displays the contents of the test file, whereas the new banner displays the actual value of banner, which is the filename and not the HTML contents of the filename.

The code of the standard and original "footer" field and the new "banner" field seem identical, yet they behave differently. Is there some other area elsewhere that needs to be dealt with to make this work?

Also, I am not understanding what exactly the <FOOT> (in all caps) is and how come in the examples even though the "header" uses <HEAD> and "footer" uses <FOOT>, the new column (called "partner" in the example or "banner" in what I am doing) uses <FOOT> and not something else.

Do I have to compile Build.pm somehow or is the Build.pm executed 'live' ?





Here is the column definitions, just in case that has something to do with it?








PLEASE HELP Pirate

(THANKS)

Last edited by:

Peter544: May 16, 2003, 9:36 AM
Quote Reply
Re: [Peter544] <%include %> insert not working In reply to
Peter, Why are you going thru all that just to include banners? Do like Pug suggested in the 2nd post above. Put the banner code in the Header field in the Categories table. Then use the <%header%> variable in your template files where you want the banner code to appear. This way no code has to be changed and each and every category can have distinct banner code. I do this and it is an easy solution.

In order to be able to include files via the <%include filename%> directive in template files, the file to be included has to be in the appropriate templates directory, i.e. if you are using the mint template set, then your file to be included would have to be in cgi-bin/admin/templates/mint/ or whatever the path is on your system.

If you want to include some file that is in another location and you are on Unix with shell access, just set up a symbolic link in the appropriate Links template dir, i.e. to include the file /home/me/master.inc into your templates as <%include master.html%> and you are using the mint template set, cd to the directory where the mint template set is located. Then type:

ln -s /home/me/master.inc master.html

better check the man page for ln on your system first....

I do this and it works fine. I was just using SSI include statements in the template files to include my various elements. However, this breaks when people call cgi scripts like add.cgi. Therefore, the above method is the universal solution.
Quote Reply
Re: [vicos2] <%include %> insert not working In reply to
I am trying to be able to have different filenames in the new text field 'banner' so that the banner text can be different from directory to directory.

<%include something%> only includes the file "something" and not whatever filename may be stored in field "something", you see what I mean?

I want to keep the fields 'header' and 'footer' open for other data so that's why I need a separate field altogether.

The way you suggest is a hard-wired include for all the directories, I need to be able to change the file for any particular category.

eventually, once this dynamic include issue is figured out, I want to do something like this:

<%if banner%> # meaning, if a non-generic banner ad is available and there is a filename of the new on available, do this
<%include banner%> # this is incorrect, still trying to figure out how to get the contents of field named banner
# the way it is right now it sees 'banner' as the filename itself.
<%endif%>
Quote Reply
Re: [Peter544] <%include %> insert not working In reply to
The following thread discusses how you can 'dynamically' include a file on a template. Look for Alex's solution.

http://www.gossamer-threads.com/...rum.cgi?post=222974;

I hope this helps.

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] <%include %> insert not working In reply to
Thanks Yogi! I think that is precisely what I am trying to do. The question is, where exactly should I stick that code alex posted?



Thanks again
Quote Reply
Re: [Peter544] <%include %> insert not working In reply to
Thanks Yogi, Alex and everyone else. I figured it out now.

All I had to do was go to admin, create a global variable with the code and it W-O-R-K-S

All this time I was messing with the misc. *.pm files only to find out it was all done via the provided interface.

I love it.

Peter
Quote Reply
Re: [Peter544] <%include %> insert not working In reply to
Interesting, how come it only works in the dynamic mode!?



When I tried to build changed pages I got this:



Quote:


A fatal error has occured:
GT::Template::Parser (478): Unable to locate template file 'test.html' in '.' or any inheritance directories at /home/sites/site3/web/search/admin/GT/Template/Parser.pm line 90.


Please enable debugging in setup for more details.




1) how come it works in dynamic mode and not the static mode?

2) where should I put the test.html to make it work

3) do I have to keep two copies of the file around, one for dynamic runs and one for static runs...?


Also, since (for now) I am using the header tag (which I want to use for something else later...) when I use it and try to build I get:



Quote:


A fatal error has occured:
GT::Template (629): Unable to create compiled template directory '/search/admin/banners/compiled'. Reason: No such file or directory at /home/sites/site3/web/search/admin/GT/Template.pm line 445.


Please enable debugging in setup for more details.

GT::Template (629): Unable to create compiled template directory '/search/admin/banners/compiled'. Reason: No such file or directory at /home/sites/site3/web/search/admin/GT/Template.pm line 445.

Last edited by:

Peter544: May 19, 2003, 12:21 AM