Do I HAVE to use a template to display model data?

From the page on Views in the Agile Toolkit Book (http://book.agiletoolkit.org/views/view.html) I get the idea using templates in mandatory to display model fields in a view. The same thing is recommended in the Envelope example.

Now it is also possible to refer to a model by its field name. So I wrote a view like this:

class View_Meter extends View {
    function init() {
        parent::init();
        $this->addClass('atk-row atk-box atk-col-3 atk-move-center');
        $m=$this->setModel('Pet');
        $m->loadAny();
        $this->add('H2')->set('Pet name: '. $m['name'] );
    }
}

Which displays the field from the retrieved row. In the model I specified that I just want to retrieve one row. (The table contains hundreds of thousand of record and I need only the last one)

So this fully serves my purpose. The model contains one row and I can disply the relevan field. Without template. (Of course I did not find out this myself)

So what is the use/advantage of a template over this simple approach? To have a view reusable? But the cost is an additional file to maintain. Or am I overlooking something?

jlinkels

Template gives more flexibility to formatting the view, especially if you have designer on your team. He can simply go and change the template.

You can also use the composite views like this, but it might require some refactoring, but it’s also perfectly acceptable.

Thanks for the explanation Romans