megaurav2002 has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

I am using Catalyst. I am retrieving some data from database and I display it to the user using templates. Now if data is too much, I want to display it to the user in more than one page. Should this be done in the template or in the controller itself. Any hints ?? Thanks!

Gaurav Talwar

Replies are listed 'Best First'.
Re: Displaying output
by naikonta (Curate) on May 14, 2007 at 14:10 UTC
    It depends on what templating system you are using. If it allows you to put more logic up to querying database and that's how you display your output, then you might stay with the template. If you don't let the templates hold some control, then you do it in your code.

    Nevertheless, additional modules could help you greatly as this kind of thing is so common that CPAN is so rich with solutions.


    Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!

Re: Displaying output
by ides (Deacon) on May 14, 2007 at 14:41 UTC

    That's really a matter of personal taste. You can do the "limiting" in either place. I weigh the decision on this type of thing based on the server resources used. If the cost of retrieving the data is high and likely to be large often, then I would put it into the controller. That way you can limit it as early as possible, for example if you know you want to page rows from the database 50 at a time, it's best to just make the SQL 'LIMIT 50'.

    If the chance that the data is too large are small ( not frequent ) and the cost to retrieve it isn't large, then I would probably opt to limit it in the template. So as not to overly limit the flexibility of the application.

    Frank Wiles <frank@revsys.com>
    www.revsys.com