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

format_title_override problem in links 3

Quote Reply
format_title_override problem in links 3
Code:
sub {
# -------------------------------------------------------------------
# Format a title
#
# Options:
# separator (required)
# The separator used to join the items.
# no_escape_separator
# Set this to a true value if you do not wish to HTML escape the separator.
# include_home
# Whether or not to include Home as the first entry. Default is no.
# link_type
# How the items should be linked:
# 0: No items linked
# 1: All items linked separately
# 2: All except the last item linked separately
# 3: All items linked as one single link (using the last item's URL)
# no_span
# Don't add the span tags around the last portion of the title. Default is to include the span tags.
#
# Note: You can override this function by creating a format_title_override global
#
my ($title_loop, %options) = @_;
return unless $title_loop; my %vars = %{GT::Template->vars};
if (exists $vars{format_title_override}) {
return $vars{format_title_override}->(@_);
} my $ret;
$options{separator} = GT::CGI::html_escape($options{separator}) unless $options{no_escape_separator};
for (0 .. $#$title_loop) {
next unless $_ or $options{include_home};
unless ($options{no_last}) {
$ret .= '<span class="lasttitle">' if $_ == $#$title_loop and not $options{no_span};
if ($options{link_type} == 1 or
($options{link_type} == 2 and $_ != $#$title_loop)) {
$ret .= qq|<a href="$title_loop->[$_]->{URL}">$title_loop->[$_]->{Name}</a>|;
}
else {
$ret .= $title_loop->[$_]->{Name};
}
$ret .= $options{separator} unless $_ == $#$title_loop;
$ret .= '</span>' if $_ == $#$title_loop and not $options{no_span};
}
}
if ($options{link_type} == 3) {
$ret = qq|<a href="$title_loop->[-1]->{URL}">$ret</a>|;
}
return \$ret;
}


I wrote this global (format_title_override) to try and not print the last item in the title with this in my category.html...

Code:

<%Links::Utils::format_title($title_loop, separator => $crumb_separator, no_escape_separator => $no_escape_crumb_separator, include_home => 1, link_type => 2, no_last =>1)%>


However, whenever I build and it gets to the category pages, it freezes...

Any suggestions...?

- Jonathan
Quote Reply
Re: [jdgamble] format_title_override problem in links 3 In reply to
That code apparantly froze my entire server!

I was looping the sub routine when it keeps going to "format_title_override" again and again.

In short, if you want the option to not display the last item (and you don't use the span), here is the code:


Code:
sub {
my ($title_loop, %options) = @_;
return unless $title_loop; my %vars = %{GT::Template->vars};
my $ret;
$options{separator} = GT::CGI::html_escape($options{separator}) unless $options{no_escape_separator};
for (0 .. $#$title_loop) {
next unless $_ or $options{include_home};
if ($options{link_type} == 1 or
($options{link_type} == 2 and $_ != $#$title_loop)) {
$ret .= qq|<a href="$title_loop->[$_]->{URL}">$title_loop->[$_]->{Name}</a>|;
}
else {
unless ($options{no_last} == 1 and $_ == $#$title_loop) {
$ret .= $title_loop->[$_]->{Name};
}
}
$ret .= $options{separator} unless $_ == $#$title_loop;
}
if ($options{link_type} == 3) {
$ret = qq|<a href="$title_loop->[-1]->{URL}">$ret</a>|;
}
return \$ret;
}

- Jonathan

Last edited by:

jdgamble: Aug 16, 2005, 6:14 AM