Random thoughts from ghenry

08 Aug

Setting Titles and CSS Depending on URLs in Catalyst with TT

written by Gavin Henry

Show your users where they are in TT

Put this somewhere in root, and then process it in your header.tt to create your page titles.


    [% SWITCH c.req.path %]
    [% CASE "home/news/" %]
        [% SET news_class = 'class="active"' %]
        <title>Linux and Open Source Support, UK - News</title>
    [% CASE "services/" %]
        [% SET services_class = 'class="active"' %]
        <title>Linux and Open Source Consultants - Services</title>
    [% CASE "about/" %]
        [% SET about_class = 'class="active"' %]
        <title>Linux and Open Source Support, UK - About</title>
    [% CASE "about/clients/" %]
        [% SET about_class = 'class="active"' %]
        [% SET clients_class = 'class="active"' %]
        <title>Linux and Open Source Support, UK - Clients</title>
    [% CASE "about/case_studies/" %]
        [% SET about_class = 'class="active"' %]
        [% SET case_studies_class = 'class="active"' %]
        <title>Linux and Open Source Support, UK - Case Studies</title>
    [% CASE "about/newsletter/" %]
        [% SET about_class = 'class="active"' %]
        [% SET newsletter_class = 'class="active"' %]
        <title>Linux and Open Source Support, UK - Newsletter</title>
    [% CASE "about/this_site/" %]
        [% SET about_class = 'class="active"' %]
        [% SET this_site_class = 'class="active"' %]
        <title>Linux and Open Source Support, UK - About Site</title>
    [% CASE "about/privacy/" %]
        [% SET about_class = 'class="active"' %]
        [% SET privacy_class = 'class="active"' %]
        <title>Linux and Open Source Support, UK - Privacy</title>
    [% CASE "about/terms/" %]
        [% SET about_class = 'class="active"' %]
        [% SET terms_class = 'class="active"' %]
        <title>Linux and Open Source Support, UK -  Terms</title>
    [% CASE "about/usage/" %]
        [% SET about_class = 'class="active"' %]
        [% SET usage_class = 'class="active"' %]
        <title>Open Source Support in Scotland UK - Usage Policy</title>
    [% CASE "about/sitemap/" %]
        [% SET about_class = 'class="active"' %]
        [% SET sitemap_class = 'class="active"' %]
        <title>Linux and Open Source Support, UK - Site Map</title>
    [% CASE "docs/" %]
        [% SET docs_class = 'class="active"' %]
        <title>Linux and Open Source Support in Aberdeen - Docs</title>
    [% CASE "faq/" %]
        [% SET faq_class = 'class="active"' %]
        <title>Linux and Open Source Experts - FAQ</title>
    [% CASE "associates/" %]
        [% SET associates_class = 'class="active"' %]
        <title>Open Source Consultants in the UK - Associates</title>
    [% CASE "support/" %]
        [% SET support_class = 'class="active"' %]
        <title>Linux Support and Services in the UK - Support</title>
    [% CASE "contact/" %]
        [% SET contact_class = 'class="active"' %]
        <title>Open Source UK Support and Services - Contact Us</title>
    [% CASE DEFAULT %]
        <title>Suretec - Open Source Support in the UK</title>
    [% END %]

Avatar On Aug 08 2006 at 10:50
phaylon wrote:

Ouch. Why not just something like a YAML file containing 'active_classes' and 'site_title' values under keys mapping to the request path?

Avatar On Aug 08 2006 at 12:26
Gavin wrote:

Because then I'd have to restart the App! ;-)

Avatar On Aug 08 2006 at 13:16
phaylon wrote:

How often do you expect to restart your production servers? :)

Avatar On Aug 08 2006 at 15:00
Jonathan Rockway wrote:

This might be better: <a href="http://blog.jrock.us/articles/Quantum%20Physics%20and%20the%20Template%20Toolkit.pod">Quantum Physics and the Template Toolkit</a>. Same idea, 3 lines of code :)

Avatar On Aug 09 2006 at 14:20
ib2218@catalystframework.org wrote:

ib2218@catalystframework.org

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.