Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re^2: Survey of Surveys on HTML Templating systems

by metaperl (Curate)
on Feb 23, 2005 at 22:02 UTC ( #433872=note: print w/replies, xml ) Need Help??

in reply to Re: Survey of Surveys on HTML Templating systems
in thread Survey of Surveys on HTML Templating systems

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}); }

Replies are listed 'Best First'.
Re^3: Survey of Surveys on HTML Templating systems
by fergal (Chaplain) on Feb 23, 2005 at 22:34 UTC
    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.

        I think you're seriously overestimating the amount of programming involved in the templates in Petal. It's deliberately designed to stop you from doing anything more than substitutions, loops over an array and conditionals. It is not a turing complete language.

        As for the mini-language for manipulating references, the only rule for the language is / means go down another level so a/b/c is $h->{a}->{b}->{c}. It hardly deserves the name mini-language.

        Imagine a page with 20 variables. The templates look almost exactly the same for Petal and Seamstress but Seamstress also requires 40 almost identical lines of Perl to find the ids and replace them.

        This means that each ID tag has to appear twice, once in the template and once in your Perl, plenty of opportunity for typos. Lets say you decide that your template should display a field that was previously omitted. Now you have to change your template _and_ add 2 more lines of Perl to make sure it gets replaced.

        I don't like mini-languages either but I would quickly become bored writing a find line and a replace line for each datum. I'd probably decide on a convention for the id tags so that the the id taq can be interpreted as a path down into a hash of data. At which point I'd have basically invented the main part of TAL. Mini-languages are bad but I'll take a small, tight mini-language any day over lines and lines of cookie cutter coding.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2021-01-15 15:53 GMT
Find Nodes?
    Voting Booth?