Re: Recall::Template - new module proposal



"ac" == arbingersys@gmail com <arbingersys@xxxxxxxxx> writes:

>> that is the general idea. but you are doing the same loop and
>> conditional but in a different place. doing it at one time to build a
>> data tree seems cleaner to me. and you can easily break up the tree
>> building into subs similarly to how you do it. conditionals are meant to
>> be in code and we agree on that.

ac> But, doesn't the data get iterated over twice, then? Once when you
ac> build the data tree, and again when it gets rendered against the
ac> template to build the rows between [%START%] and [%END%]? In my loop,
ac> when you call render() the only thing happening is a s/// against the
ac> template, then output. There is no further looping. So there is only
ac> one iteration over the data.

you still have to build a data tree sometime. and if it is nested you
deal with that too in both places.

>> well, they have to be created somewhere. most sites have plenty of
>> nesting of structures. and i recently created CMS::Simple (not published
>> yet) which uses template::simple and makes it easier to share data and
>> templates across many pages. it also has content filtering (for links,
>> markup, escaping, etc.)

ac> I think Template::Simple is an interesting module with definite
ac> usefulness. However, I think the motives behind it and
ac> Recall::Template are different. Template::Simple seems driven by
ac> building elegant data structures to be converted into templates
ac> with a single call. Recall::Template is designed to keep
ac> everything but the simplest logic (variables) out of the
ac> templates. This is why the templates are broken into sections. I
ac> don't even want the templates to be able to include other
ac> templates, or tell the code where to start and end iterative
ac> output. I want everything to be decided by the code -- e.g. which
ac> templates to include or exclude, in what order, and at what time,
ac> what formatting to use for row output, etc.

that makes sense for some applications. i built CMS::Simple to much of
that on top of template::simple. it loads, parses and filters contents,
places it in data trees and then renders and publishes output.


ac> Let's say you query a table in SQL for

ac> select distinct category from products order by category

ac> and you store 'category' in @groups. Then, you will hit the database
ac> (or maybe an in-memory data structure) again for the products in that
ac> group during the loop, e.g.

ac> for (@groups) {
ac> my %h;
ac> $h{'[%group%]'} = $_;
ac> print $rt->render('groups', %h);
ac> my @details = get_details($_); # Hit DB for products/details in
ac> category
ac> for (@details) {
ac> print $rt->render('details', %{$_});
ac> }
ac> }


ac> If the 'groups' template section looked like

ac> <tr><td colspan="3"><b>[%group%]</b></td></tr>

so it seems you look in the hash for its keys and then replace those
with their values. am i correct that only things found in the hash then
are replaced? if i have a [%foo%] in the template but not in the hash it
is unchanged?

ac> <tr>
ac> <td>[%product%]</td>
ac> <td>[%inventory%]</td>
ac> <td>[%price%]</td>
ac> </tr>

ac> you've just done simple nested output. You could even add a variable
ac> to tally total product inventory at the end, in a template section
ac> named 'tally', for instance.

that is a basic loop expansion which is good. how would you handle it if
a <td> had its own list or hash to render?

>> when you render a value you can't just replace any occurance of the name
>> token because it might be in the real text. so most/all templaters use a
>> delimiter to demark which are template tokens and
>> markup. template::simple does [%NAME%] which is a common style. but the
>> [% and %] can be changed with options to the constructor.

ac> Gotcha. This is left entirely to the discretion of the programmer. As
ac> you can see in my [reworking of the] example above, you can use
ac> whatever tag pattern you want. Recall::Template doesn't care, and
ac> neither do I.

this reinforces my understanding that it is the keys in the hash that
drive the expansion, not markup in the template. that is reversed from
how template::simple (and most other templaters) do it as they parse out
template markup and replace all of it.

uri

--
Uri Guttman ------ uri@xxxxxxxxxxxxxxx -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
.



Relevant Pages

  • Re: perl is slick
    ... > Todd W. wrote: ... hash value) of an object somewhere in the object tree. ... Template::Toolkit template. ... references) are basically the same thing so you can use both transparently. ...
    (perl.beginners)
  • Re: Recall::Template - new module proposal
    ... if during the loop you wanted to hide ... ac> it again against the template. ... ac> DETAIL1 DETAIL2 ... >> markup delimiters. ...
    (comp.lang.perl.modules)
  • Re: beginner c++ homework questions --=[let me try one more time]=--
    ... Write compilable code and actually compile it. ... >functionality to the ISPAccount class and/or the Money class. ... You seem to be trying to loop through each ... goes: template. ...
    (comp.lang.cpp)
  • Re: data encryption advice needed
    ... The hash would probably work. ... If the templates are XML files, ... file system signed and would then verify the signatures before using them. ... > template that came from trusted source. ...
    (microsoft.public.dotnet.security)
  • Re: data encryption advice needed
    ... > The hash would probably work. ... If the templates are XML files, ... to extract template data from the final data. ... > file system signed and would then verify the signatures before using them. ...
    (microsoft.public.dotnet.security)