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

Bill Moseley moseley at hank.org
Sun Feb 22 17:15:07 GMT 2009


On Sun, Feb 15, 2009 at 11:05:20AM +0100, Aristotle Pagaltzis wrote:
> Your templates should build up the page inside-out, and
> they should not be calling *any* methods in your model. As far as
> possible they should only be using stashed variable values. If
> you call any methods they should only be helper methods from the
> context like `uri_for`.

Hope that quote is not out of context.

So are you saying you should never do this?:

    Hello [% user.first_name | html %]

That instead you should have in your controller:

    $c->stash->{first_name} = $user->first_name;

and then:

    Hello [% first_name | html %]

Maybe "first_name" is considered an attribute instead of a method, but
I do this:

    From: [% user.full_email %]

Which the full_email method uses first_name, last_name, and email
attributes.

And a wrapper template might want to do this:

    [% buddies = user.buddies; PROCESS display_buddies IF buddies %]

Perhaps that technically belongs in the (chained) controller, but my
controllers would quickly become a tangled mess if I had to call every
method in the controller for every view possibility.

Yes, perhaps TT provides too much power (to abuse) but that kind of
usage really helps keep the controllers clean.  The controller
converts the request for a user into a user object, but it's up to the
view to decide to display the user's first name only or their full
name, IMO.

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




More information about the Catalyst mailing list