in reply to
Template toolkit Adding Values to Variable
You might consider separating your business logic from your presentation code a bit more. You are doing things with tt that probably should be done in Perl. The paper
Enforcing Strict Model-View Separation in Template Engines
is a good start.
HTML template entanglement survey
Comment on
consider separating your business logic from your presentation code
In Section
Seekers of Perl Wisdom