Hi Yaerox, glad to see you experimenting with TT2.

I read most of this thread and here are some observations:

In the first example code, once you have aliased your table as u you can just refer to it as that.

I disagree with the monkm who recommended not using TT2 because of its complexity. It is true that it will require more time to learn, but at the end you will have a more powerful system.

I strongly recommend not running DB perl code in your template. Sure you can, but why in the world would you? You are still obviously going to have a perl program that uses the template; that's where you should be doing the Perl work.

An exception could be when you can retrieve a set of records with a one-line dbh call and then feed them to a TT loop. But when you are going to be processing the data or it's a multiline SQL statement, there is no way that should be in the template. That is the whole point of the template! To separate your code languages.

Another exception could be that you retrieve the records with DBI in your Perl program and pass the record set into the Template where a Macro might process some format or something like that, or look up a string in a language library. In some cases the greater benefit is in keeping the Perl code clean.

Typically, however, I have always tried to do every bit of processing I could in a Perl program, building up a highly complex data structure of hashes of arrays of hashes of ..... and then passing that in to the template as much intact as possible.

HTH

Remember: Ne dederis in spiritu molere illegitimi!

In reply to Re: Template::Toolkit - How do i access alias-based results? by 1nickt
in thread Template::Toolkit - How do i access alias-based results? by Yaerox

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.