Chapter 10. Page views

Table of Contents

Intro
Inheritance tree
Automatically exported variables
Page views usage
When to create additional views
Page view's TPL files "classic" structure

Intro

Page views are one of the pillars of the paradigm of separation between logic, data and presentation. They are solely responsible for the presentation part. No other classes are allowed to output HTML (except for debugging purposes). Each page (WP file) has at least one view defined in its init() method.

All page views are inherited from Web_Page_View class.

By default Tangra framework uses » Smarty template engine. It is wrapped in tple_smarty module. Theoretically you can use other template engine if you create wrapper around it (i.e. class that implements I_Tple) but since Smarty is the leading and most powerful template engine - it does not make much sense.

All presentation HTML code is contained in so called Tpl files. Those files are used by the template engine to produce final HTML output. Simplified it works like this:

  • In your WP class you create one or more views in init()
  • In run() or event handling method you "export" variables with $this->export('somevarname', $somevar)
  • run() or event handling method returns view
  • $SITE calls view's show() method
  • View creates object of type Tple (which is wrapper around Smarty tple), passes all exported variables to it.
  • Tple compiles the TPL file and sends output to output buffer (i.e. shows it in browser)