For awhile, I've been pretty religious about not putting code in my html. In perl, I've been using TemplateToolkit, doing all processing before handling off to the templates. In cases where things become complicated, I would write TT plugins. In java/jsp, I would always use taglibs instead of jsp scriptlets.

Recently I've been "pushed" into two projects: one in PHP, another in Mason, both of which tend to embed code in html (of course, neither have to, even PHP has its own template systems: Smarty or Flexy.) I'm especially pleased with my first encounter with Mason, although I haven't yet got into something too complicated. I was delighted to find the component inheritance concept in Mason, and think it probably is the "correct" model for webpages with a common layout.

This short note is just a reminder to myself that good things can happen when one ventures out into something one philosophically/religiously rejects, this applies to frameworks as well as languages.

Replies are listed 'Best First'.
Re: First encounter with Mason
by siracusa (Friar) on Aug 31, 2005 at 02:35 UTC

    There's nothing inherently wrong with putting Perl code in your HTML template files. What's wrong is putting Perl code that does something other than format content for presentation in your HTML template files. Don't do that.

    I think the "religion/philosophy" you cite is correct, but your interpretation of its intent was wrong ;)

Re: First encounter with Mason
by gargle (Chaplain) on Aug 31, 2005 at 07:07 UTC

    Hello,

    An interesting read can be found at MVC Pattern.

    In short:

    Model
    The Model handles the state of the application. The Model does not know anything about HTML, or web servers or anything like that.
    View
    The View is the representation of the user interface. In web based MVC systems, a view can be implemented using a template that renders an HTML page.
    Controler
    The Controller handle the incoming HTTP requests. The Controller receives user requests, and translates them into actions that the Model should take. Then it selects the appropriate View to handle the response.

    Catalyst uses the MVC pattern. Mason can do the templating (as noted by the orginal poster). More can be found by googling.

    if ( 1 ) { $postman->ring() for (1..2); }
Re: First encounter with Mason
by perrin (Chancellor) on Aug 31, 2005 at 03:53 UTC
    Your point about trying new things and not getting stuck in your ways is a good one. In this particular case I would add that I often do similar "inheritance" schemes with TT, by adjusting the include path based on the current type of request, so I can override the header for a certain area of the site, etc.