In the beginning there was the simple Web page. Web sites were built
using basic HTML with content coded directly in the pages. Things
were simple then.
As the Web evolved and became an important information and entertainment
medium, more and more Web sites became Web applications with more
sophisticated presentation and user interaction requirements.
To cope with this additional complexity, techniques were developed to
apply templating and modular design concepts to Web page construction.
Most Web development environments now have tools available to aid in the
development of sites using templating and modular construction techniques.
The PHP Web environment has many such tools to choose from, some of which
are listed in the resources section. This guide uses the PhpTAL templating
system as a Plug-in to the php.MVC Web application framework.
PhpTAL is a port of the successful Zope templating engine. Using PhpTAL we
will build some Web application pages, starting with a simple page to
introduce basic templating techniques and dynamic data. We will then quickly
move on to more complex page layouts using page components to build the pages
with common sections like headers, footers, navigation bars, contents etc.
Although we are focused on using PhpTAL, most of the page layout techniques
we will use in this guide should be easily adapted for use with the various
other PHP templating systems.
There is currently much discussion on the pros and cons of the various
templating techniques. The benefits and costs of these approaches to page
design is a research topic in itself and is beyond the scope of this guide.
To get the most from this guide you should at least be familiar with basic HTML
page construction and style sheet (CSS) usage. It would probably be a good idea
to have the PhpTAL documentation at hand when working through the examples.
See the reference section for links to sources of online documentation.
A working knowledge of how php.MVC applications are setup and operate
will be helpful, as we will not cover the setup and operation of a php.MVC
application in much detail in this guide. Please refer to the other guides
and examples as required.
Web page templating systems allow the developer to separate her business
logic (a report generating class and methods, for example) from the actual
HTML pages. The programmers can now focus on the applications business classes,
while leaving the designers to concentrate on page layout and design issues.
As stated above PhpTAL is a port of the Zope templating engine. PhpTAL uses the
Template Attribute Language (TAL). TAL is defined as attributes to standard
HTML tags, for example:
<title tal:content="title">Page Title</title>
This statement specifies that the contents of the title
page tag be replaced with the value we assign to the TAL variable
"title", for example "Welcome To My Site".
So the result after processing could look something like:
<title>Welcome To My Site</title>
Pages containing TAL attributes are still valid XML documents. It is now possible
for the page designer to open the page in an WYSIWYG editor or Web browser, and
the structure of the page will be unchanged. In our code fragment above, the
text Page Title will act as a place holder for
the actual dynamic text in the title tag.
We will see how to set the TAL template variables in our classes in a later
section of the guide.
PhpTAL supports the common template variable replacement techniques and other
sudo-programming operations such as loops, as found in most popular template
engines. Additionally PhpTAL implements Macros, or the Macro Extension for
TAL (METAL). PhpTAL Macros provide a more sophisticated method of building
documents from sections of other pages.
By using these templating features we can greatly reduce the coupling of our
business code to the presentation, more easily create a common look-and-feel
design, and eliminate much repetition and maintenance associated with modern
Web applications.
Please refer to the The Zope Book: Appendix C, "Zope Page Templates Reference", for more
detailed information on TAL. See the reference section for links to the relevant
resources.
Unpack the archive to a Web accessible directory on your Web server. Open
Main.php in an editor and set the application path and the phpmvc library
path to reflect your installation. Note: These paths are absolute paths,
not URL type paths. The path statements should look something like:
/* ---------- Application Paths ---------- */
// Set php.MVC library root directory
$appServerRootDir = 'C:/WWW/phpmvc-base'; // no trailing slash
// Set the application path
$moduleRootDir = 'C:/WWW/phpmvc-test/PageLayoutTAL'; // no trailing slash
/* ---------- Application Paths ---------- */
To run the example application, point your browser to
index.html file.
For more information on setting up php.MCV applications, please refer to the
other resources available in the
User Guides directory.