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

GLinks 3: Extending Crumb Titles to Custom Templates

Quote Reply
GLinks 3: Extending Crumb Titles to Custom Templates
Hi,

In the new GLinks 3 luna templates, there's a neat crumb title showing where you are relative to the home page.

For eg. Home >> Logon, Home >> Add Link, Home >> Top Rated Links etc. etc.

I'm trying to figure out how to extend this to work on additional custom templates. For eg. I've added a Contact Page template and I want "Home >> Contact Page" to appear at the top of the page just like it does on the standard luna templates.

The relevant code is:
Code:

<div class="crumb"><%Links::Utils::format_title($main_title_loop, separator => $crumb_separator, no_escape_separator => $no_escape_crumb_separator, include_home => 1, link_type => 2)%></div>


When I call this in my custom template, it returns nothing at all. I just get the output <div class="crumb"></div>.

It has something to do with the setting of $main_title_loop I assume.

Any ideas on getting this to work ?

Regards,
Peter Puglisi
www.ausfreedom.com
Ultimate Freedom is our game.
Quote Reply
Re: [rocco] GLinks 3: Extending Crumb Titles to Custom Templates In reply to
$main_title_loop isn't a magic variable, it is passed in from the code, but isn't for your custom code. You need to create it yourself. The first argument to format_title (in this case $main_title_loop) should be an array of hashrefs with keys Name and URL (since most people don't link the last item, you can get away with just specifying Name).

So to generate the necessary structure that format_title is expecting you'll have to write a global like:
Code:
sub {
return [
{ Name => Links::language('LINKS_TOP'), URL => "$CFG->{build_root_url}/$CFG->{build_index}" },
{ Name => shift, URL => shift }
];
}
Then in the templates, do:
Code:
<%set main_title_loop = gen_title("Contact Page")%>

PS: pugdog's solution also works.

Adrian

Last edited by:

brewt: Apr 16, 2005, 3:20 PM
Quote Reply
Re: [rocco] GLinks 3: Extending Crumb Titles to Custom Templates In reply to
If your custom page is being generated by a script that doesn't provide that tag, you'll have to enter the code to create that variable.

Code:
$results->{main_title_loop} = Links::Build::build('title', Links::language('LINKS_ADD_SUCCESS'), "$CFG->{db_cgi_url}/add.cgi");

and you'd return or pass $results (or %$results).

or
Code:
my $mtl = Links::Build::build('title', Links::language('LINKS_ADD_SUCCESS'), "$CFG->{db_cgi_url}/add.cgi");

and in the Site::HTML::build or return () functions, you would assign {...., main_title_loop => $mtl, ...}


Pretty much you need to return a tag "main_title_loop" that is "built" from the above sort of function call.

That tag is then sent through the html-based function call you printed.

Basically, you call Links::Build::build's "title" function, with the text-string you want, and an optional override-URL for the _last_ item to link to it, if the second paramter is not a category name. It returns an array of hashrefs [{Name => url}, {Name => url}..]

This is what is "breadcrumbed" by the routine in the template.

It's kind of cool, but you need to tell it what you want to end up bread crumbed, it's not automatic.

It sets the Home> or whatever your defined value is, as the first parameter, so passing in

Links::language('LINKS_ADD_SUCCESS')

would return:

Home > Sucessfully Added

Depending on what you had set for your language code.




PUGDOG´┐Ż Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [brewt] GLinks 3: Extending Crumb Titles to Custom Templates In reply to
  
Thanks. I tried this but got:
Code:

Not an ARRAY reference at /var/www/cgi-bin/lrd/admin/Links/Utils.pm line 485.


From Links/Utils.pm:
Code:

485: for (0 .. $#$title_loop) {
next unless $_ or $options{include_home};
$ret .= '<span class="lasttitle">' if $_ == $#$title_loop;
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;
}


Edit:
I just saw your edited post. Will try that now.
Edit2:
Adrian, I still get the above error with you solution. Interested to know why though.

Regards,
Peter Puglisi
www.ausfreedom.com
Ultimate Freedom is our game.

Last edited by:

rocco: Apr 16, 2005, 4:35 PM
Quote Reply
Re: [pugdog] GLinks 3: Extending Crumb Titles to Custom Templates In reply to
Thanks for this. I modded the contactpage plugin like so:

Code:

print Links::SiteHTML::display(contact_form => {
main_title_loop => Links::Build::build('title', "Contact Page", "$CFG->{db_cgi_url}/contact.cgi")
});


This all works fine.

Regards,
Peter Puglisi
www.ausfreedom.com
Ultimate Freedom is our game.