Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Multiple link templates - broken images - random link

Quote Reply
Multiple link templates - broken images - random link
Please Help

I implemented multiple link templates, and the correct template comes up
for each category, but my images are not displaying. They have broken image icons.

Here's the code I used for multiple link templates:
-------------------------------------------------------------------
1) Create Global: link_include

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

-------------------------------------------------------------------
2) Add new column to "category" properties:
New Column: Link_Template
Field Data: link_bands

-------------------------------------------------------------------
3) Create New link template:
link_bands.html

-------------------------------------------------------------------
4) Call Global via category.html:
<%loop links_loop%>
<%link_include%>
<%endloop%>


-------------------------------------------------------------------
-------------------------------------------------------------------
Template selection works well, except for broken images and mp3 links.
Which both display properly when looping via:

<%loop links_loop%>
<%if category_id == 1%>
<%include link_bands.html%>
<%endif%>
<%endloop%>

But image links break when using:

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

-------------------------------------------------------------------
I am using the the following html code in "link_bands.html:

<a href="<%db_cgi_url%>/jump.cgi?ID=<%ID%>" target="_blank"><img src="<%relative_image%>" height="image" width="150" border="0"></a>

-------------------------------------------------------------------
This is the global that "breaks" when implementing multiple link templates
Global: relative_image

sub {
my ($rec) = @_;
my $id = $rec->{ID};
if ($rec->{Image})
{
my $links_db = $DB->table('Links');
my $fh = $links_db->file_info( 'Image', $id );
my $location = $fh->File_RelativePath;
return qq~../../files$location~;
}
else
{
return "";
}
}

-------------------------------------------------------------------
I should also mention, that I have implemented a random link to
show on home page. (random from specific category, if paid)

Random Link within Bands category for Home Page
This is what is being used at supportmusicians.com

sub {

my $id = shift;
my $db = $DB->table ('Links','CatLinks');

my $sth;

if ($CFG->{payment}->{enabled})
{
$sth = $db->select({ 'CatLinks.CategoryID' => '1'},
GT::SQL::Condition->new(
isValidated => '=' => 'Yes',
ExpiryDate => '>=' => time,
ExpiryDate => '<' => FREE
)
);
}
else
{
$sth = $db->select({ 'CatLinks.CategoryID' => '1'},
GT::SQL::Condition->new(
isValidated => '=' => 'Yes'
)
);
}
my $total = $db->hits;
my $rand = int( rand($total+1) );

if($rand == 0)
{ $rand = 1; }

my $count = 0;
my $html ='';

my @output;
while (my $hit = $sth->fetchrow_hashref) {

if($count+1 == $rand)
{
$html = Links::SiteHTML::display('link', $hit);
}
$count++;
}
return $html;
}

-------------------------------------------------------------------
OK one more thing...

I WAS simply doing this (in category.html) before implementing multiple link templates:

<%if category_id == 1%>
<%include link_bands.html%>
<%else%>
<%include link.html%>
<%endif%>

This worked perfectly for both the random link on the home page,
and when displaying links in the Band websites category.

BUT..........

In "link_bands.html", I need to use the following:

<%if category_id == 1%>
show mp3 link and image
<%else%>
dont show it
<%endif%>

The real problem after all this is:
When used this (old) way from home page, I do not seem to have the
variable "category_id" when random link is called from home.html.
Thus I cannot ask the question... <%if category_id == 1%>.

When using multiple link template method, I have broken links.
Multiple templates will work, because I would not have to ask the
question... <%if category_id == 1%>. I would know that it was
category 1 because of the template I am in.
This is the method I would prefer to use.

On home.html I call <%random_link%>. See global above.

-------------------------------------------------------------------
Someone please help... It seems that the simplest things are so complicated

I believe the reason for the "relative_image" global was to implement
the home page random link.

Anyone have a global that will return the category id of a link might also be a solution for me?

See at http://www.supportmusicians.com
It is currently NOT using multiple link templates. Note the difference in the
link on the home page and the ones in "Band Websites" categories. Buttons and
links are missing on home page because no variable "category_id" by the time
it gets to my template, so my question <%if category_id == 1%> doesn't work.

The multiple link template method doesnt nee to ask <%if category_id == 1%>,
but I get the broken links that way. Maybe someone can just fix my global for
"relative_image"? It works fine without multiple link templates.

Thank you,
Chris
RGB World, Inc. - Software &amp; Web Development.
rgbworld.com
Quote Reply
Re: [rgbworld] Multiple link templates - broken images - random link In reply to
I wish we rookies could delete or edit our own posts,
It sure would make this board a lot easier to solve problems.
But seems I can't edit my post, I will try to explain the solution here

All the code in my previous (super long) post... is correct, except that:

In my <%random_link%> global:
$html = Links::SiteHTML::display('link_bands', $hit);

should be:
$html = Links::SiteHTML::display('link_bands', $hit);

And my statement:
In "link_bands.html", I need to use the following:

<%if category_id == 1%>
show mp3 link and image
<%else%>
dont show it
<%endif%>

Simply was a mistake in thinking (and code). I no longer need to ask
<%if category_id == 1%> when using EITHER method of multiple
link templates.

So I can now use either:

<%loop links_loop%>
<%if category_id == 1%>
<%include link_bands.html%>
<%else%>
<%include link.html%>
<%endif%>
<%endloop%>0


OR
<%loop links_loop%>
<%link_include%>
<%endloop%>0


in category.html, depending on whether or not I "implemented multiple link templates".


It also wasn't very clear in that previous post that these were 2 different methods of
using multiple link templates. So minus all my babbling, there is some good code
in this post.

Too bad I can't clean it up :-)

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

Last edited by:

rgbworld: Mar 12, 2005, 2:15 PM
Quote Reply
Re: [rgbworld] Multiple link templates - broken images - random link In reply to
Have you been able to get this working in Search_results.html?


Sandra Roussel
Chonsa Group Design - Fresh Start Housing