Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Short description ... read more

Quote Reply
Short description ... read more
Hi, All

I am using this global to show the short description of the link.
######################################
sub {
my $tags = shift;
my $desc = $tags->{Description} or return "No description on this template";
length $desc < 300 and return $desc;
my $short = substr ($desc, 0, 300);
$short =~ s/\s\S+?$//;
$short .= "<b> ... read more</b>";
return $short;
}
#####################################


What I want is at the end of the short description a "read more" hyperlink to a detailed page. I tried <%detailed_url%> but that doesn't work. And "read more" must also work when there are less than 300 characters in my example.


Thanks all.
Ron
Quote Reply
Re: [rsahertian] Short description ... read more In reply to
Try;

Code:
my $id = $tags->{ID};
my $detailed_url = $CFG->{build_root_url} . "/Detailed/$id.html";
$short .= "<b> ... <a href="$detailed_url">read more</a></b>";

That should work :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Short description ... read more In reply to
Hi Andy,

I've got an:
Unable to compile 'short_description'

where exactly must I place your piece of code, Andy?

Thanks,
Ron
Quote Reply
Re: [rsahertian] Short description ... read more In reply to
Change the line in Andy's code above (it wont like all the quotation marks):

$short .= qq~<b> ... <a href="$detailed_url">read more</a></b>~;
Quote Reply
Re: [afinlr] Short description ... read more In reply to
Sorry, you are correct. I should have escaped those "s :(

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Short description ... read more In reply to
Is it possible to expand this a little so we could use something like

<%global(Field,120)%>

Field - this is the field we want to shorten
120 - the number of characters

Thanks!
Quote Reply
Re: [Payooo] Short description ... read more In reply to
Give this one a go :)

Code:
sub {

my $id = $_[0];
my $desc = $_[1];
my $chars = $_[2] || '300';
my $build_url = $CFG->{build_root_url};

if (!$desc) { return "No description on this template"; }

length $desc < $chars and return $desc;
my $short = substr ($desc, 0, $chars);
$short =~ s/\s\S+?$//;
$short .= "<b> ... read more</b>";
return $short;

my $detailed_url = "$build_url/Detailed/$id.html";
$short .= qq|<b> ... <a href="$detailed_url">read more</a></b>|;

}

...you can call it with;

<%global($ID,$Description,'300')%>

Basically, you need to pass in ID, Description and how many charachters you want to use :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!

Last edited by:

Andy: Oct 8, 2004, 7:17 AM
Quote Reply
Re: [Andy] Short description ... read more In reply to
Thanks Andy Smile


return "No description on this template" if !$chars; <- doesn't work if the field is empty

Changed return $short; and added build_detail_url + build_extension

Is it OK to use it this way?


sub {
my $id = $_[0];
my $desc = $_[1];
my $chars = $_[2] || '300';
my $build_detail_url = $CFG->{build_detail_url};
my $build_extension = $CFG->{build_extension};

return "No description on this template" if !$chars;

length $desc < $chars and return $desc;
my $short = substr ($desc, 0, $chars);
$short =~ s/\s\S+?$//;

my $detailed_url = "$build_detail_url/$id$build_extension";
$short .= qq|<b> ... <a href="$detailed_url">read more</a></b>|;
return $short;
}
Quote Reply
Re: [Payooo] Short description ... read more In reply to
Mmm. what happens if you change;

Code:
return "No description on this template" if !$chars;

to

Code:
if (!$desc) { return "No description on this template"; }

Does that work?

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Short description ... read more In reply to
YES! Smile

Thank you!