Namesco Open Source Projects

Free Stuff on the Intertubes


without comments

Welcome to ZTal.

Full documentation and examples are available at the ZTal github wiki

ZTal is an open source project to replace the View and Form capabilities of Zend Framework with the PHPTAL templating engine.

While Zend Framework is a powerful and useful framework for building MVC (Model / View / Controller) based PHP web application, it does have a few limitations and less-than-wonderful design aspects that make true MVC separation difficult to achieve and mixing of markup and PHP inevitable. Replacing the View and Form rendering components of Zend Framework with PHPTal (a fast and capable templating engine based on the Zope Template Attribute Language) it is much easier to keep full separation of markup and PHP while also benefiting from PHPTAL’s excellent translation and macro support.

ZTal provides the glue that allows Zend Framework to use PHPTAL templates as Views and Layouts while also allowing PHPTAL to access Zend Framework’s Translation facilities. In particular:

  • ZTal replaces Zend View and Layout objects with PHPTAL equivalents.
  • ZTal has macros to render Zend_Form and other common Zend objects such as Zend_Date and Zend_Currency.
  • ZTal has access to Zend_Translate, unifying translation support.
  • ZTal handles PHPTAL translation namespaces where they are not supported natively in Zend_Translate.
  • ZTal provides plural support to PHPTAL’s translation capabilities.
  • ZTal can use Zend_Cache to cache rendered PHPTAL pages.
  • ZTal provides a Zend_Mail subclass to use templates with email.

What advantages are gained from separating PHP code from View templates? Many PHP developers believe that PHP itself is the most powerful and capable templating engine available and in many ways this is true. However, with the power comes the responsibility: the responsibility to write high quality, secure code, the responsibility to write easy to maintain php intermixed with html, css and javascript, the responsibility to enforce true MVC design patterns despite the temptation to just put that mysql database connection code directly in the template…

By using a separate templating engine (especially one that makes use of PHP difficult) there is a clear distinction between the business logic and the display logic of your application. Pick the right templating engine and you can gain even more – easy template re-use, templates that can display placeholder output statically (i.e. without needing to run the php code while designing), easy translation support, better security and better standards compliance.

PHPTAL is a PHP implementation of the Zope Template Attribute Language (TAL). TAL is an XML-based language where template instructions are added to a layout in the form of attributes and tags. The original TAL document (with optional placeholder content) is a fully XML compliant document and the generated output is also fully XML compliant. PHPTAL takes care of correctly escaping variable content in many cases as well as setting the correct HTML attributes for ‘checked’, ‘selected’ and similar. PHPTAL includes localisation and internationalisation support right in at the core using a simple to use XML namespace allowing you to develop multi-lingual applications with very little effort and it has a powerful macro system allowing you to create libraries of display components for re-use across your application and applications. In addition, as a compiled-template technology, it is fully compatible with OpCode caches and PHP accelerators.

Written by rgoldsmith

July 22nd, 2010 at 4:08 pm

Posted in