Book Image

Smarty PHP Template Programming and Applications

By : Hasin Hayder, Joao Prado Maia, Lucian Gheorghe
Book Image

Smarty PHP Template Programming and Applications

By: Hasin Hayder, Joao Prado Maia, Lucian Gheorghe

Overview of this book

<p>Smarty is a templating engine for PHP. Designers who are used to working with HTML files can work with Smarty templates, which are HTML files with simple tags while programmers work with the underlying PHP code. The Smarty engine brings the code and templates together. The result of all this is that designers can concentrate on designing, programmers can concentrate on programming, and they don't need to get in each others way so much. Even if you are developing a site on your own, Smarty is a powerful way to make your code clearer to you and others, as well as easier to debug and modify later.</p>
Table of Contents (18 chapters)
Smarty PHP Template Programming and Applications
Credits
About the Authors
About the Reviewer
Preface
Index

Automatically Loading a Filter


One obvious downside of the previous method of loading a filter plug-in is that you need to use the load_filter method on every template that you want the filter to execute. What if you want the filter to run on your entire website or application? This can be done by automatically loading filters with the autoload_filters Smarty property.

We can do this by changing the value of this variable directly in the Smarty source code. Look for the Smarty.class.php file and change the autoload_filters variable, as shown next:

<?php
// inside Smarty.class.php ..

    /**
     * This indicates which filters are automatically loaded into Smarty.
     *
     * @var array array of filter names
     */
    var $autoload_filters = array(‘output’ => array(‘append_benchmark_data’));

// ..
?>

The change above will tell Smarty to always load the given output filter plug-in. You will still need to create the plug-in file and name the function within it as explained in the...