Straight from the reference manual for Template Toolkit, we see the following example for the IF directive:
[% IF age < 10 %] Hello [% name %], does your mother know you're using her AOL account? [% ELSIF age < 18 %] Sorry, you're not old enough to enter (and too dumb to lie about your age) [% ELSE %] Welcome [% name %]. [% END %]
Here we see variable output based on age and we see the use of display logic to handle it. But, a different way to think about solving this problem is to have a controller dispatch to 3 separate sub-actions, one for each age bracket, each of which points to a different view. Why would one go to this trouble? Because it scales to possible model actions later: logging each visit based on age, for example.

In Catalyst code, using control logic to handle age:

package MyApp::C::Login; sub login : Path('/login') { my ( $self, $c ) = @_; my $age = $c->req->params->{age} ; if ($age < 10) { $c->forward('under10'); } elsif ($age < 18) { $c->forward('under18'); } else { $c->forward('welcome'); } sub under10 : Private { my ( $self, $c ) = @_; $c->model('Login')->incr_under10; $c->stash->{template} = 'under10.tt'; } # and so forth
Now this might seem like overkill, but consider this more extensive example of a server database for Catalyst whose view is implemented in tt. Instead of two views, one for user and one for admin, we have a number of IF and UNLESS checks for admin interspersed in the code.

So, to summarize.

  1. moving "display logic" from templates to controllers can make HTML more readable. The extensive example above could be refactored into two pages, one for admin and one for users and therefore be more readable.
  2. moving "display logic" from templates to controllers insures scalability should additional model actions need to occur atomically with certain view actions.

In reply to The fine line between control and display logic by santonegro

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.