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

Aristotle Pagaltzis pagaltzis at gmx.de
Sun Feb 15 10:05:20 GMT 2009


* Gene Selkov <selkovjr at observercentral.net> [2009-02-05 00:30]:
> 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.

Use Chained dispatch in Catalyst to accumulate all the necessary
data in the stash, go to a specific template, and then implicitly
use wrapper templates to build out the surrounding bits.

Mason gives you tools to build a page outside-in (going from
generic to specific parts). In Catalyst you use Chained dispatch
for that. 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`.

There should be no application logic in the templates, only
display logic. We all know that, right? Well, selecting which
component template or which block to use for rendering is more
often application logic than display logic. You should be very
suspicious every time you put a conditional in your templates.
I’m not saying display logic has no conditionals, there are
plenty, but stare long and hard at your boolean expressions.
Should they really be calculated in the template or should they
be passed in through the controller via the stash?

Think about coupling; consider how much infrastructure you would
have to mock up in order to unittest a template. If you need the
whole app set up and running for the template to work, you’re
doing it wrong. (I’m not perfect at this by a long shot yet.
Short-sighted pragmatism is easier than forethought, and much
that is claimed to be forethought is really empty dogmatism.)

Basically, to design your Catalyst app properly you need to
disregard about 90% of Mason.

Imagine it like zoom-in/zoom-out sequence. Chained dispatch zooms
in on the most specific part of the page, then wrapper templates
zoom out to the full picture.

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>



More information about the Catalyst mailing list