logo





GradeBook released!
Oct, 2008
Solstice adds a grade book to its toolkit!

New Versions!
April, 2008
A new version of all our software is available!

CommonView Released
April, 2008
Check out our latest collaborative tool.

RESTful Web Services
Jan, 2008
Solstice provides support for RESTful development.

How to work with views

The basics

It is the view's job to organize all the data and print out the html. Due to our templating system, each view is kept very clean and succinct. This is an example of a view:

Perl
package HelloWorld::View::Home; use strict; use warnings; use 5.006_000; use base qw(Solstice::View); our ($VERSION) = ('$Revision: 191 $' =~ /^\$Revision:\s*([\d.]*)/); our $template = 'home.html'; 1;

This is a trimmed down, simple view. Its only job is to specify a template to be painted. It passes no data into the template and while simple and clean is not extremely useful.

Each view is responsible for defining a template path. In our example we specified the template files be stored in the templates directory, so Solstice would expect our home.html file to be in the root of the templates directory.

generateParams

Solstice automatically runs a method called generateParams in each view. This is the method where you will want to organize your data and create parameters for your template. It should look something like this:

Perl
sub generateParams { my $self = shift; my $model = $self->getModel(); $self->setParam('title', $model->getTitle()); }

This example assumes that your view has a model, and the model has a method called getTitle. This view has created a param called title and passed in the title of the model down to the template to be used.

If you have a list of models, and want to add them in a contextual loop, you can do something like the following:

Perl
sub generateParams { my $self = shift; my $list = shift; my $iterator = $list->iterator(); while (my $model = $iterator->next()) { $self->addParam('models', { title => $model->getTitle(), }); } }

More on views

Want to do more with your view? You can find a complete API for views here.

To read more about the templates that views populate, see How to work with templates.