Gossamer Forum
Home : Products : Gossamer Links : Discussions :

force line break

Quote Reply
force line break
Hi,

not quite sure if this is a plugin post or discussion so apologies if it is in the wrong place.

I am using a template global to display my category path above results. The trouble is it can be very long and mucks up my page formatting. I have experimented with using css to insert a break but the tabe size stays the same even though the text is effectivly wrapped inside it.

I want to stick with 100% tabe widths to maintain multi user platform/screen sizes.

Here is the global I use to display category path which I pulled from another post.

sub { my ($rec) = @_; my $id = $rec->{ID}; my $db = $DB->table ('Category','CatLinks'); my $sth = $db->select ( { 'CatLinks.LinkID' => $id }, ['Category.ID', 'Category.Full_Name'] ); my $cat; while (my ($id,$name) = $sth->fetchrow_array) { $name =~ s/ /_/g; $cat = "<a href=$CFG->{build_root_url}/$name>$name</a>"; } return $cat; }

Can anyone suggest how I could force this to break up after say n number of characters, just one line break should be sufficient.

In link.html I use
<!--code for path-->
<%if query%><font face="Verdana" size="1">Results From&gt;<%link_category_id%><%else%> <a href="<%db_cgi_url%>/jump.cgi?ID=<%ID%>"><%Title%></a> <%endif%>
<!--end path code-->

to call the global.

Many thanks as always to everyone,

Cheers
KevM
Quote Reply
Re: [KevM] force line break In reply to
try doing something like:
Code:
my $disp_name;
my $i = 1;
my $cut = 5;

foreach my $cat (split /\//, $name) {
if ($i == $cut) {
$i = 0;
$disp_name .= "<br>";
}
$disp_name .= "/" . $cat;
$i++;
}

and then use $disp_name instead of $name in the text for the link (ie, <a href="$name">$disp_name</a>)

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [fuzzy logic] force line break In reply to
Hi Philip,

thank you for the code, unfortunately it doesn't work, I think for 2 reasons, I do actually use $Name in the text for the link, it gets called in the global i posted first and I do not think a global can call a global

I did try calling the global code you posted into another global but it did not like that.

I think I might try nesting tables in the links search results screen as i can't get it to be happy with anything else, css and word-break it really gets annoyed with.

Cheers
KevM
Quote Reply
Re: [KevM] force line break In reply to
Hi,

This is for anyone elses benefit really who might also be having the same problem with formatting of long category paths or URLs in the results whilst trying to maintain 100% widths

My solution is far from ideal and a bit hit and miss to use but is, I think, the only html solution to the problem.

It's based on a 'normal' CSS property but applied to a table cell (because as you may find out if you play with it tables and css are frustrating as they seem to operate independently)

add this css to a table (no need to set global styles anywhere), set your width (in pixels not %)

<td style="word-wrap: break-word;" width="400">

This then wraps the text, regardless of whether it has line breaks or not inside the cell as oppose to expanding the cell which is normal behaviour and very annoying. If you put this inside another table you can maintain 100% widths for the rest of the page, just the bit that you specify in the cell will not expand greater than 400 or whatever you set it to.

Hit and miss because you don't know where the line breaks will occur in your text. Ideally you'd want it at a / in the path or url but thats probably not a possible task.

Hope this little trick helps

Cheers
KevM