Get Smarty

Donate

Donate Bitcoin Bitcoin
Paypal

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Sites Using Smarty

Largest classified with thousands of ads at Shoppok

Buy cheap eyeglasses from Cheapglasses123.com and save up to 80%.

Buy prescription glasses from www.australiaglasses.com and save.

Cheap Glasses Now On Sale at GlassesPeople.com. Starts At $7.95.

Where to buy discount wedding dresses and cheap smart dresses free shipping - Weddingdresstrend.com

Find Wedding Dresses Online at Canada from Ca-dresses.com

Find your local domestic cleaner

Brautkleider auf Topwedding.de

Find free files to download on allwhatyouwant.net

Looking For Affordable Wedding Dresses 2015 at Best Prices On TDBridal.com

Advertisement

Name

registerDefaultPluginHandler() — register a function which gets called on undefined tags

Description

void registerDefaultPluginHandler(mixed callback);

Register a default plugin handler which gets called if the compiler can not find a definition for a tag otherwise. It uses the following parameters:

  • callback defines the PHP callback. it can be either:

    • A string containing the function name

    • An array of the form array($object, $method) with $object being a reference to an object and $method being a string containing the method-name

    • An array of the form array($class, $method) with $class being the class name and $method being a method of the class.

If during compilation Smarty encounters tag which is not defined internal, registered or loacted in the plugins folder it tries to resolve it by calling the registered default plugin handler. The handler may be called several times for same undefined tag looping over valid plugin types.

Example 14.38. Default Plugin Handler Example


<?php

$smarty = new Smarty();
$smarty->registerDefaultPluginHandler('my_plugin_handler');

/**
 * Default Plugin Handler
 *
 * called when Smarty encounters an undefined tag during compilation
 * 
 * @param string                     $name      name of the undefined tag
 * @param string                     $type     tag type (e.g. Smarty::PLUGIN_FUNCTION, Smarty::PLUGIN_BLOCK, 
                                               Smarty::PLUGIN_COMPILER, Smarty::PLUGIN_MODIFIER, Smarty::PLUGIN_MODIFIERCOMPILER)
 * @param Smarty_Internal_Template   $template     template object
 * @param string                     &$callback    returned function name 
 * @param string                     &$script      optional returned script filepath if function is external
 * @param bool                       &$cacheable    true by default, set to false if plugin is not cachable (Smarty >= 3.1.8)
 * @return bool                      true if successfull
 */
function my_plugin_handler ($name, $type, $template, &$callback, &$script, &$cacheable)
{
    switch ($type) {
        case Smarty::PLUGIN_FUNCTION:
            switch ($name) {
                case 'scriptfunction':
                    $script = './scripts/script_function_tag.php';
                    $callback = 'default_script_function_tag';
                    return true;
                case 'localfunction':
                    $callback = 'default_local_function_tag';
                    return true;
                default:
                return false;
            }
        case Smarty::PLUGIN_COMPILER:
            switch ($name) {
                case 'scriptcompilerfunction':
                    $script = './scripts/script_compiler_function_tag.php';
                    $callback = 'default_script_compiler_function_tag';
                    return true;
                default:
                return false;
            }
        case Smarty::PLUGIN_BLOCK:
            switch ($name) {
                case 'scriptblock':
                    $script = './scripts/script_block_tag.php';
                    $callback = 'default_script_block_tag';
                    return true;
                default:
                return false;
            }
        default:
        return false;
    }
 }

?>

  

Note

The return callback must be static; a function name or an array of class and method name.

Dynamic callbacks like objects methods are not supported.

Comments
No comments for this page.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Author:
Email: (not shown)
What is 8 plus 1? (Are you human?)

Advertisement

Sponsors [info]

UK Web Hosting @webhost.uk.net
Best Web Hosting @rshosting.com
Web Hosting UK @webhostinguk.com
Unlimited Web Hosting @infrenion.com
App Entwicklung @morphodo.com
First Click Internet Marketing @fcinternetmarketing.com
Credit Card Processing Company