=head1 NAME Maypole::Manual::View - Maypole View Classes =head1 DESCRIPTION In a large application, you will almost certainly want to customize the layout and design of the output pages. This task may even be the purview of a separate team of HTML designers rather than the programmers. Since a typical programmer will try to avoid touching HTML as much as possible and a typical designer will try to avoid touching Perl code, programmers have evolved a system of templating to separate the concerns of programming and designing. One of the core concepts in Maypole is the I, and this is responsible for routing the data produced in the model class into the templates produced by the designers. Of course, there are a great many possible templating systems and styles, and so there can be a great many possible Maypole view classes. Each view class will take the data from the controller, locate a template to be processed, and hand the whole lot to its preferred templating module, which will then do the hard work of filling in the template and coming up with the output. You can choose whatever Maypole view class you want, but the default view class is L, and it feeds its data and templates to a module called the Template Toolkit. =head2 The Template Toolkit The Template Toolkit, written by Andy Wardley, is a very powerful and generic templating system. It provides its own little formatting language which supports loops, conditionals, hash and array dereferences and method calls, macro processing and a plug-in system to connect it to external Perl modules. Its homepage is C. There are several good introductions to the Template Toolkit available: you should have one installed as L; there's one at L, and of course there's the "Badger Book" - I, by Andy et al. C We'll present a brief introduction here by deconstructing some of the templates used by Maypole applications. For more deconstruction, see L, which is an entire chapter dealing with the factory supplied templates. Here's a template that could be called for the front page of the example beer database application, C. [% INCLUDE header %]

The beer database

[% FOR table = config.display_tables %] [% END %]
List by [%table %]
The first thing to note about this is that everything outside of the Template Toolkit tags (C<[%> and C<%]>) is output verbatim. That is, somewhere in the output you're guaranteed to see

The beer database

Inside the tags, magic happens. The first piece of magic is the C<[% INCLUDE header %]> directive. This goes away and finds a file called F
- don't worry about how it finds that yet, we'll come to that later on - and processes the file's contents as though they were right there in the template. Our F
file happens not to contain any C<[% %]> tags, but if it did, they would be processed in the same way as the ones in F. The next piece of magic is this line: [% FOR table = config.display_tables %] We're seeing a lot of things here at once. C is where we should start looking. This is a template variable, which is what templates are all about - templating means getting data from somewhere outside and presenting it to the user in a useful way, and C is a prime example of data that we want to use. It's actually an object containing configuration parameters for this Maypole application, and one of the methods is C, which returns a list of the database tables that we're supposed to show. In the application, we probably said something like BeerDB->config->display_tables([qw[beer brewery pub style]]); This stores the four values - C, C, C and C