[Catalyst] TT custom virtual methods available to all pages.

Felix Antonius Wilhelm Ostmann ostmann at websuche.de
Wed Apr 23 16:17:52 BST 2008


i love such liddle funktions as FILTER :)

in View::TT

__PACKAGE__->config(
    {
        CATALYST_VAR => 'catalyst',
        ...
        FILTERS => {
            yesno     => sub {
                $_[0] ? 'yes' : 'no';
            },
            onoff     => sub {
                $_[0] ? 'on' : 'off';
            },
        },
    },
);


so i can write in the template

Newsletter: [% user.newsletter | yesno %]


or your mk_hash:

[% somedata | mk_hash %]


Rajeev Cyrus schrieb:
> Greetings.
>
> One of my TT pages required some massaging of data that I decided to 
> do via referencing a subroutine in a template variable, eg:
> $c->stash->{mk_hash} = \&mk_hash;
>
> I would like to use this stashed variable on all of my templates so my 
> question is:
> Where is the best place to initialize and set this variable? Where 
> should i declare the mk_hash method? Is there some way I can configure 
> catalyst to set certain template variables when the application starts?
>
> Thanks!
>
> -Rajeev Cyrus
>
>
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: 
> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
>
>


-- 
Mit freundlichen Grüßen

Felix Antonius Wilhelm Ostmann
--------------------------------------------------
Websuche   Search   Technology   GmbH   &   Co. KG
Martinistraße 3  -  D-49080  Osnabrück  -  Germany
Tel.:   +49 541 40666-0 - Fax:    +49 541 40666-22
Email: info at websuche.de - Website: www.websuche.de
--------------------------------------------------
AG Osnabrück - HRA 200252 - Ust-Ident: DE814737310
Komplementärin:     Websuche   Search   Technology
Verwaltungs GmbH   -  AG Osnabrück  -   HRB 200359
Geschäftsführer:  Diplom Kaufmann Martin Steinkamp
--------------------------------------------------




More information about the Catalyst mailing list