[Catalyst] template design issue: varibales stand-alone components

Bill Moseley moseley at hank.org
Thu Feb 5 00:24:40 GMT 2009


On Wed, Feb 04, 2009 at 05:25:41PM -0600, Gene Selkov wrote:
> On Wed, 4 Feb 2009, J. Shirley wrote:
>
>> The Catalyst method is quite simple, since it tries to adhere to the
>> MVC design patterns.
>>
>> You would not set the variable in your templates, instead in the controller.
>>
>> sub action_name : Local {
>>    my ( $self, $c ) = @_;
>>   $c->stash->{surname} = $c->model('LDAP')->get_ldap_surname($id);
>> }
>>
>> Then your template gets 'surname' and you can just do:
>>
>> Hello <% $surname %>!
>
> I understood as much. The problem I am grappling with is the complexity 
> of the web pages I have to present, with many different states and  
> transitions. There is no way I can code for that with a single template.

Hopefully, not, but you can come close.

> I am used to the idea that I can have a parent template (autohandler in  
> Mason), which provides basic navigation and status display for the site;  
> autohandler then invokes another template (a master template for that  
> particual page's content) which itself uses various odd templates for  
> recurrent elements in the page, and the change of state sometimes 
> consists of replacing one little component of a sub-component with a 
> component of a totally different nature (say, a name is replace with a 
> list of names, or a blank display component is replaced with a message 
> resulting from a prior action).

Maybe I've had too much TT Koolaid (try some, it's yummy), but my
one-word answer would be "WRAPPER".

My templates for each page typically only contain the markup to render
the specific data for that request.  Wrapper templates handle
everything else (menus, layout, columns, banners, everything) is
pulled in from nested wrapper templates.  It's very rare that an
include file is referenced more than once.


Also, this makes me cringe a bit:

    Dear Dr.  <% $surname %>!

I would think you would hide that in an object (or hash if you like as
TT doesn't care), and do:

    Dear Dr. [% user.surname %]

so you don't spend all your coding time populating the stash in your
controllers.


-- 
Bill Moseley
moseley at hank.org
Sent from my iMutt




More information about the Catalyst mailing list