Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Survey of Surveys on HTML Templating systems

by fergal (Chaplain)
on Feb 23, 2005 at 20:06 UTC ( #433846=note: print w/ replies, xml ) Need Help??


in reply to Survey of Surveys on HTML Templating systems

None of the surveys I've seen look at Petal which is based on Zope's TAL/ZPT. As far as I'm concerned there is no other way to do HTML/XML templates.

Example:

Welcome back <b tal:content="user/name">Sample Username</b>, you last logged in <i tal:content="user/last_login">Sat 23rd Aug</i>

When you look at this in dreamweaver or a browser you'll see

Welcome back Sample Username, you last logged in Sat 23rd Aug

(view source on this page and you'll see that I have simply pasted in the code)

When you run this through the Petal engine you pass in a hash of data, say $h. Assuming

$h = { user => { name => "Fergal Daly" last_login => "Feb 22nd" } }
The processed output will be

Welcome back Fergal Daly, you last logged in Feb 22nd

As you can see, the HTML beforehand is well formed, includes sample values for the dynamic parts and all you have to do with Dream weaver is apply styles to the sample data and all will be well. At template compile time, all the sample data is discarded and then at run time, the real data is inserted.

Of course TAL handles loops and conditionals etc. The thing that takes the most getting used to is that it's a little verbose. Unfortunately this is a necessary side effect of being truly compatible with XML/HTML.


Comment on Re: Survey of Surveys on HTML Templating systems
Select or Download Code
Re^2: Survey of Surveys on HTML Templating systems
by perrin (Chancellor) on Feb 23, 2005 at 20:28 UTC
    I'm in the process of updating my article, and it will include Petal. The HTML_Tree module referred to in the current version is a dead project now.
Re^2: Survey of Surveys on HTML Templating systems
by metaperl (Curate) on Feb 23, 2005 at 22:02 UTC
    Everything you said about Petal applies to Seamstress. However, the advantage of Seamstress is that you don't need to learn a mini-language.

    So let's take the same content:

    Welcome back <b tal:content="user/name">Sample Username</b>, you last logged in <i tal:content="user/last_login">Sat 23rd Aug</i>
    And when you look at this in dreamweaver or a browser you'll see
    Welcome back Sample Username, you last logged in Sat 23rd Aug

    And assuming

    $h = { user => { name => "Fergal Daly" last_login => "Feb 22nd" } }

    The processed output will be

    Welcome back Fergal Daly, you last logged in Feb 22nd

    Now for the big difference

    Of course TAL handles loops and conditionals etc.
    Seamstress does not. Perl has loops and conditionals and sees no need for their re-invention.
    The thing that takes the most getting used to is that it's a little verbose. Unfortunately this is a necessary side effect of being truly compatible with XML/HTML.
    I agree with you here, but I personally could have it no other way either. Here is how seamstress would template the same thing:
    require html::welcome_form; my $tree = html::welcome_form->new; my $user_name = $tree->look_down('tal:content' => 'user/name'); $user_name->replace_content($hash->{user}{name}); my $last_login = $tree->look_down('tal:content' => 'user/last_login); $last_login->replace_content($hash->{user}{last_login});

    or with a loop

    for my $content (qw(name last_login)) { $tree->look_down('tal:content' => $content) ->replace_content($hash->{user}{$content}); }
      I don't get it, from the example you gave, seamstress requires a whole load of extra Perl code as well as a HTML template.

      As for a mini-language it's almost non-existent. Petal's loops are very simple

      <table> <tr tal:repeat="thing user/things"> <td tal:content="thing/name">Widgets </td>: <td tal:content="thing/count">10</td> </tr> </table>
      this will produce one row for every element of $h->{user}->{things}.

      That's as complex as you can get with loops. You just supply an array and Petal loops over it. This forces you to prepare all your data in advance and then just pump it into the template (although you can call methods as well as doing hash lookups so it's possible to lazily produce the data only as it's needed).

        I don't get it, from the example you gave, seamstress requires a whole load of extra Perl code as well as a HTML template.
        I would say that Seamstress requires a lot of Perl and nothing but id tags in the HTML (a standard thing) while in contrast Petal requires very little Perl but more programming in the XML/HTML. Looking at this another way, the learning curve for Seamstress is nothing but object-oriented Perl an object-oriented API for tree manipulation. The learning curve for Petal is Perl to the level of references and a mini-language for manipulating those references.

        Seamstress can unroll tables in two ways: using a row-oriented iterator method and it can also create tables using grid coordinates.

        here is a reference to my query about alternating table rows in Petal... it is different from how Seamstress does it.

        I have said time and again here that I do not like mini-languages. I spent enough time learning Perl and HTML so that I dont want to be concerned with hybrid technologies which are no more powerful but do require me to remember yet another set of rules and exceptions and limitations. To each his own, but keep me away from mini-languages personally.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://433846]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2014-09-21 08:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (168 votes), past polls