Just another Perl shrine | |
PerlMonks |
Re: Template::Toolkit - How do i access alias-based results?by 1nickt (Canon) |
on Jul 13, 2015 at 23:07 UTC ( [id://1134605]=note: print w/replies, xml ) | Need Help?? |
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 Section
Seekers of Perl Wisdom
|
|