Saturday, 3 May 2008

Zend and XSLT as a template engine

If you have XML data that you need displayed, turn off automatic view rendering within you bootstrap file with

$controller->setParam('noViewRenderer', true);

This gives you more control over how Zend renders views. Then, in your controller action , create a new view and assign some variable from you application logic. You need to tell the view where the script is to execute. You do this using $view->setScriptPath('...');. Once this points to the right directory, you can add a script in there you want the view to run. You do this by calling the render method of the view instance you create, passing it a single string parameter as the script you want it to run. As the contents of the script is returned, the whole thing needs to either be echoed or printed from the controller action.

Within the view script, print anything you want to be rendered on the page. So here you can pair up the xml data passed from the controller action using $this and an XSLT stylesheets you want to transform.

Brilliant hey? I sort of get this stuff.

No comments: