Random thoughts from ghenry

08 Aug

Showing content in Catalyst with TT depending on URL

written by Gavin Henry

Show submenus depending on where your users are.

Do something similar to this:


[% SET page = c.req.path %]
[% IF (matches = page.match('about')) %]
                                <ul>
                                    <li [% clients_class %]><a href="/about/clients/">Clients</a></li>
                                    <li [% case_studies_class %]><a href="/about/case_studies/">Case Studies</a></li>
                                    <li [% newsletter_class %]><a href="/about/newsletter/">Newsletter</a></li>
                                    <li [% this_site_class %]><a href="/about/this_site/">This Site</a></li>
                                    <li [% privacy_class %]><a href="/about/privacy/">Privacy</a></li>
                                    <li [% terms_class %]><a href="/about/terms/">Terms</a></li>
                                    <li [% usage_class %]><a href="/about/usage/">Usage</a></li>
                                    <li [% sitemap_class %]><a href="/about/sitemap/">Site Map</a></li>
                                </ul>
                            [% END %]

Avatar On Sep 23 2006 at 07:35
Chris wrote:

Personally i've been doing this with an arrayref of hashes stored in the stash:
eg:
$c->stash->{menu} = [
  { title => 'heading1', href => 'link someplace'},
  { title => 'heading2', items => [
    { title => 'item1', href=> 'link'}
...etc,

then just process it in the template using nested FOR loops. t works quite well since you can use $c->forward to delegate it to a common subroutine, then either pass arguments to that routine, or make a generic set of navigation links, then push extra controller-specific headings onto the end.

Your captcha is:






Only the comment itself is required, but if you supply your email we'll gladly load your gravatar. We won't use your email for any other purpose or sell it to nigerian business men. Promise.
A live preview of your comment will appear in this box.