Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Short_desc problem

Quote Reply
Short_desc problem
Hi All

I am having a slight problem with the short_desc global and that is i would like to display the companies description upto 300 characters under there link, EASY eh! just change the:
Code:
length $desc <80 and return $desc; to length $desc <300 and return $desc;


And theres the problem, when i build i get the descripton that breaks my tables and flys throught the page giving me a bottom scroll bar. E.G:

Description:
Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah.......

What i am trying to achive is have the short_desc show it in 2-3 lines like this:

Description:
Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah
Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah
Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah......

I just Can't figure out how to do this, i have tried editing the global, not working.



Can you give me some help.

Thanks
Kirk


--------------------------------------------------

Life isn't like a box of chocolates ... it's more like a jar of jalapenos. What you do today might burn your ass tomorrow.
Post deleted by RedRum In reply to

Last edited by:

RedRum: Mar 3, 2002, 4:21 AM
Quote Reply
Re: [mekro] Short_desc problem In reply to
Hi

Can anyone help me with this problem please...........

Kirk


--------------------------------------------------

Life isn't like a box of chocolates ... it's more like a jar of jalapenos. What you do today might burn your ass tomorrow.
Quote Reply
Re: [mekro] Short_desc problem In reply to
I don't know the global, but I have a feeling it was designed to return 80 character lines.

If you post your global I'lll look at it.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Short_desc problem In reply to
Hi pugdog

Thanks for the reply, as for the code i have included it here:

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


--------------------------------------------------

Life isn't like a box of chocolates ... it's more like a jar of jalapenos. What you do today might burn your ass tomorrow.
Quote Reply
Re: [mekro] Short_desc problem In reply to
How about something like:

Code:
sub {
my $desc = $_[0]->{Description};
my $len = length $desc or return "No description on this template";
my $split = int($len / 3);

$len < 80 and return $desc;

$desc =~ s/(.{$split}[^\s]+)/$1<br>/g;

return $desc;

}

I've made it so it won't split words...it will wait until it hits a space. The 3 is the number of lines to split it into, although it isn't fool proof.

Last edited by:

RedRum: Mar 6, 2002, 1:51 PM
Quote Reply
Re: [mekro] Short_desc problem In reply to
Code:
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 .= " ...";
return $short;
}


This will cut the string at 300 characters, in the middle of the word, if that is where it falls.

If you want to give Paul's regex a try, insert it

my $short =~ /(.{$split}[^\s]+)/;

Paul didn't test it, I didn't test it, but using pauls string, this should return the first
match of 300 characters, breaking on whitespace.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Short_desc problem In reply to
>>Paul didn't test it<<

I did a quick test using:

foo foooooo foooooooooo foooo fooooooooooo fooooooooo fooooooooooooooooo fooooooooo foooo

....and I ended up with:

foo foooooo foooooooooo foooo fooooooooooo
fooooooooo fooooooooooooooooo fooooooooo
foooo
Quote Reply
Re: [RedRum] Short_desc problem In reply to
Hi Paul

Thanks for the code it works, however i there seems to be one problem with it and that is i am using that code to shorten the desciptions on the catagory pages.

I have tried changing the amaount of characters to 80 or 100 but it still places the entire description on the catogory pages even if the description has 2000 characters.

Is there a way to shorten the description.

Kirk


--------------------------------------------------

Life isn't like a box of chocolates ... it's more like a jar of jalapenos. What you do today might burn your ass tomorrow.
Quote Reply
Re: [mekro] Short_desc problem In reply to
Yeah you can shorten it like:

$desc = substr($desc, 0, 100);
Quote Reply
Re: [Paul] Short_desc problem In reply to
Hate to bring up an ancient post, but is there a way to do this and strip out all the html formatting, such as the table tags, ul, li, <P>, etc, and just leave the text??

</not a clue>
Quote Reply
Re: [Dinky] Short_desc problem In reply to
No guarantees, but you could try;

$var =~ s|\<(.+?)\>||g;

... just before the formatting is done (otherwise, it will give you the wrong length, because the HTML charachters will be removed, even though they were counted).

Hope that helps.

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_desc problem In reply to
Tried that before, keep getting:
Unable to compile 'short_desc': Global symbol "$var" requires explicit package name at (eval 28) line 5
kicked back...

</not a clue>
Quote Reply
Re: [Dinky] Short_desc problem In reply to
LOL.. you need to replace $var with $desc Wink I just used $var as an example... so you could see the regex format.

After;

Code:
length $desc <= 300 and return $desc;

...add;

Code:
$desc =~ s|\<(.+?)\>||g;

Hope that helps.

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!