Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Multiple link templates?

Quote Reply
Multiple link templates?
My directory needs to have different "link" layouts for certain categories. My problem is that i only know how to get the catagory template to parse the link.html template meaning that all my links in my directory will be using the same template for the link layouts.

Anyone know a simple way i could have a category template parse another template for the link layout?

Thanks

Terry

Last edited by:

Camelman: Jan 30, 2005, 3:34 PM
Quote Reply
Re: [Camelman] Multiple link templates? In reply to
There are many different ways to accomplish this:

You can edit your category_template field in your category,

create a new template for the category, and use a loop.

<%loop links_loop%>
<%if category eq "category name"%>
<%include link.html%>
<%elsif category eq "etc"%>
<%include link2.html%>
<%endif%>
<%endloop%>

or something like that...

If you have many different link templates you want to use, you might concider adding a field to your category db called link_template...

and you would use...

<%include $link_template%>

Just ideas... Hope I can help,

- Jonathan
Quote Reply
Re: [jdgamble] Multiple link templates? In reply to
==================================================================
If you have many different link templates you want to use, you might concider adding a field to your category db called link_template...

and you would use...

<%include $link_template%>
===============================================================

I think the second option would be best for me. My lack of knowledge with linksql and coding got me lost.

This is what i tried: I added a (char) column to the catagory database called link_template. Then i edited the category and in the link_template field added link2.htm assuming it would parse that template for the links. I then modified the category template and added <%include $link_template%> to it.

This is the error i got:

Error: Can't load included file: '/home/thepromo/public_html/cgi-script/linkssql/admin/templates/default/$link_template'. Reason: No such file or directory

I tried many different variations and other ideals with no luck.

If you could explain in a little more in detail, what i need to do i would greatly appreciate it.
Quote Reply
Re: [jdgamble] Multiple link templates? In reply to
Quote:
If you have many different link templates you want to use, you might concider adding a field to your category db called link_template...

and you would use...

<%include $link_template%>
Unfortunately, this isn't supported with the current version of GT::Template. It will be supported in Gossamer Links 3.x though.

Adrian
Quote Reply
Re: [Camelman] Multiple link templates? In reply to
Because you can't <%include $link_template%>, you can add a global like this:

Code:

sub {
my $rec = shift;
my $name = $rec->{Link_Template};
return Links::SiteHTML::display($name, $rec);
}


This should work. Assuming your field in your db is called Link_Template. You also don't want to store the ".html" in your field. Your default value for the field (in example) would be "link".

You can name the global something like <%link_include%>, and call it the same way:

<%loop links_loop%>
<%link_include%>
<%endloop%>

Hope that works! Good luck.

- Jonathan
Quote Reply
Re: [brewt] Multiple link templates? In reply to
Now that I think about it, couldn't you do something like this?

<%loop links_loop%>
<%Links::SiteHTML::display($Link_Template, $_)%>
<%endloop%>

The $_ does not pull the hash right, but there has got to be a way...

Any ideas?

- Jonathan
Quote Reply
Re: [jdgamble] Multiple link templates? In reply to
________________________________________________
sub {
my $rec = shift;
my $name = $rec->{Link_Template};
return Links::SiteHTML::display($name, $rec);
}

_______________________________________


Your global worked perfectly :)

Thanks

Terry
Quote Reply
Re: [brewt] Multiple link templates? In reply to
Adrian

Any ideal when Gossamer Links 3.x will be ready to be relased?


Thanks
Quote Reply
Re: [Camelman] Multiple link templates? In reply to
Yeah, but I think there is a way to do it without even having to have a global.

<%loop links_loop%>
<%Links::SiteHTML::display($Link_Template, $_)%>
<%endloop%>


will print the template, but it will not bring in the record information. Maybe if I change $_ to something like $links_loop->{0} or something. Any ideas anyone? (I know you figured out your problem, but this is going to drive me crazy if I don't figure it out!)

- Jonathan
Quote Reply
Re: [jdgamble] Multiple link templates? In reply to
When I use <%link_include%> in cool.html, I get the following error:
--------------------------------------------------------------------------------------------------------------------
A fatal error has occured:
Invalid SiteHTML method: 'site_html_'. at /home/virtual/site129/fst/var/www/cgi-bin/links/admin/Links/SiteHTML.pm line 238.
Please enable debugging in setup for more details
--------------------------------------------------------------------------------------------------------------------

This works fine when used in category.html:
<%loop links_loop%>
<%link_include%>
<%endloop%>

It also does not work from: modify_select.html, new.html, rate.html and a few others.
How can I get <%link_include%> to work from cool.html?

I thought that anyplace that called <%include link.html%>,
Could now just call
<%link_include%>

Multiple link template is all fixed in 3.0 right?

Thank you,
Chris

RGB World, Inc. - Software &amp; Web Development.
rgbworld.com
Quote Reply
Re: [rgbworld] Multiple link templates? In reply to
Here's my working version of <%link_include%> global.
sub {

my ($rec) = @_;
my $id = $rec->{ID};
my $catLinksTable = $DB->table('CatLinks');
my $catlinks_sth = $catLinksTable->select( { LinkID => $id } );
my $hit = $catlinks_sth->fetchrow_hashref;
my $catID = $hit->{CategoryID};

my $table = $DB->table('Category');
my $cat_sth = $table->select( { ID => $catID } );
my $cat_hit = $cat_sth->fetchrow_hashref;
my $name = $cat_hit->{Link_Template};
;
return Links::SiteHTML::display($name, $rec);

}


Called via category.html like this:
<%loop links_loop%>
<%link_include%>
<%endloop%>

Called via cool.html like this:
<%loop link_results_loop%>
<%link_include%>
<%endloop%>

I have replaced <%include link.html%> with <%link_include%> everywhere
in occurs throughout the .html templates and it works perfectly now.

FYI, Link_Template is a custom Category column that holds the name of
the template (minus the .html) to use when displaying links in that category.

Chris
RGB World, Inc. - Software &amp; Web Development.
rgbworld.com

Last edited by:

rgbworld: Mar 13, 2005, 1:04 PM
Quote Reply
Re: [brewt] Multiple link templates? In reply to
Brewt,

please describe in detail how to create different "link.html" templates in "Links SQL 3.0" in the manual you are creating.
BTW: is there an easier way to achieve this rather than using code like
<%loop links_loop%> , etc. ?


Many thanks,

Erich



Last edited by:

erichcyber: Mar 19, 2005, 7:02 PM
Quote Reply
Re: [erichcyber] Multiple link templates? In reply to
In Gossamer Links 3.0, if you added a custom column named Link_Template to the Category table, then you could put the following at the top of your link.html:
Code:
<%if Link_Template and Link_Template ne 'link.html' and Link_Template contains '.'%>
<%include $Link_Template%>
<%endparse%>
<%endif~%>
What that's doing is if the Link_Template variable exists and passes some tests, then it will include that file and end parsing the link.html template. Otherwise you will get your default of the regular link.html template.

Adrian

Last edited by:

brewt: Mar 19, 2005, 8:43 PM