From efc7114f5380893011627ffb70ebe148b92c6439 Mon Sep 17 00:00:00 2001 From: andrey Date: Wed, 20 Feb 2002 22:29:28 +0000 Subject: [PATCH] *** empty log message *** --- docs.sgml | 307 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 229 insertions(+), 78 deletions(-) diff --git a/docs.sgml b/docs.sgml index 6f2c0a3d..bb9a576a 100644 --- a/docs.sgml +++ b/docs.sgml @@ -1224,6 +1224,24 @@ $smarty->unregister_compiler_function("tplheader"); + + trigger_error + + + void trigger_error + string error_msg + [int level] + + + + This function can be used to output an error message using Smarty. + level parameter can be one of the values + used for trigger_error() PHP function, i.e. E_USER_NOTICE, + E_USER_WARNING, etc. By default it's E_USER_WARNING. This function + was added to Smarty 2.0. + + + is_cached @@ -6178,98 +6196,231 @@ s m o k e r s a r e p. . . type is one of these plugin types: - - function - modifier - compiler - prefilter - postfilter - resource - insert - + + function + modifier + compiler + prefilter + postfilter + resource + insert + name should be a valid identifier (letters, numbers, and underscores only). + + Some examples: function.html_select_date.php, + resource.db.php, + modifier.spacify.php. + + + The plugin functions inside the plugin files must be named as follows: +
+ + smarty_type_name() + +
+
+ + The meanings of type and name are + the same as before. + + + Smarty will output appropriate error messages if the plugin file it + needs is not found, or if the file or the plugin function are named + improperly. + + + + Note that even though pre/postfilters still have to be correctly + named even though the names are not really used for anything. + +
- - Making Custom Plugins - - - functions - - - -custom function plugin - - - - - modifiers - - - -modifier plugin - + + Writing Plugins + + Plugins can be either loaded by Smarty automatically from the + filesystem or they can be registered at runtime via one of the + register_* API functions. They can also be unregistered by using + unregister_* API functions. + + + For the plugins are registered at runtime the name of the plugin + function does not have to follow the naming convention. + + + If a plugin depends on some functionality provided by another plugin + (as is the case with some plugins bundled with Smarty), then the proper + way to load the needed plugin is this: + +require_once SMARTY_DIR . 'plugins/function.html_options.php'; + + + + As a rule, Smarty object is always passed to the plugins as the last + parameter. + - - - - compiler functions - - - -compiler function plugin - + functions + + + void plugin_name + array $params + object &$smarty + + + + All attributes passed to template functions from the template are + contained in the $params as an associative + array. Either access those values directly, e.g. $params['start'] or + use extract($params) to import them into the symbol table. + + + The output of the function will be substituted in place of the + function tag in the template (fetch function, for + example). Alternatively, the function can simply perform some other + task without any output (assign function). + + + If the function needs to assign some variables to the template or use + some other Smarty-provided functionality, it can use the supplied + $smarty object to do so. + + + See also: + register_function, + unregister_function. + + + + + function plugin with output + +<?php +/* + * Smarty plugin + * ------------------------------------------------------------- + * File: function.eightball.php + * Type: function + * Name: eightball + * Purpose: outputs a random magic answer + * ------------------------------------------------------------- + */ +function smarty_function_eightball($params, &$smarty) +{ + $answers = array('Yes', + 'No', + 'No way', + 'Outlook no so good', + 'Ask again soon', + 'Maybe in your reality'); - - - - prefilters - - - -prefilter plugin - + $result = array_rand($answers); + echo $answers[$result]; +} +?&rt; + + + + function plugin without output + +<?php +/* + * Smarty plugin + * ------------------------------------------------------------- + * File: function.assign.php + * Type: function + * Name: assign + * Purpose: assign a value to a template variable + * ------------------------------------------------------------- + */ +function smarty_function_assign($params, &$smarty) +{ + extract($params); - - - - postfilters - - - -postfilter plugin - + if (empty($var)) { + $smarty->trigger_error("assign: missing 'var' parameter"); + return; + } - - - - template resources - - - -resource plugin - + if (!in_array('value', array_keys($params))) { + $smarty->trigger_error("assign: missing 'value' parameter"); + return; + } - - - - inserts - - - -insert plugin - + $smarty->assign($var, $value); +} +?&rt; + + + + modifiers + + + + modifier plugin + - - - - - + + + + compiler functions + + + + compiler function plugin + + + + + + prefilters + + + + prefilter plugin + + + + + + postfilters + + + + postfilter plugin + + + + + + template resources + + + + resource plugin + + + + + + inserts + + + + insert plugin + + + + + + + Debugging Console