Gossamer Forum
Quote Reply
Shorten the Title
Heya ll,

Been trying to hack together a little global that will do nothing but take the title from a link and shorten it to however long I want it to be. Not working that well - but then I also know next to nothing about writing globals - can anyone help? Smile

Code:
sub {
my $link = $_[0];
if (length $link->{Title} > 20) {
$link->{Title} = substr($link->{Title}, 0, 20) . '...';
}
return $Title;
}

Safe swoops
Sangiro
Quote Reply
Re: [sangiro] Shorten the Title In reply to
Here's the short_description global you may be able to modify to suit the title.

sub {
my $tags = shift;
my $desc = $tags->{Description} or return "No description on this template";
length $desc <100 and return $desc;
my $short = substr ($desc, 0, 100);
$short =~ s/\s\S+?$//;
$short .= " ...";
return $short;
}

Regards

minesite
Quote Reply
Re: [minesite] Shorten the Title In reply to
Even easier would be to pass the variable in...

Code:
sub {
my $length_l = 100;
my $value = $_[0] or return "No value...";
length $value < $length_l and return $value;

my $short = substr ($value, 0, $length_l);
$short =~ s/\s\S+?$//;
$short .= " ...";
return $short;
}


..and call with;

<%global_name($FieldName)%>

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!