From eb2e03ae9b9616167737a6d9196a65eae40a95c0 Mon Sep 17 00:00:00 2001 From: andrey Date: Wed, 20 Feb 2002 21:11:48 +0000 Subject: [PATCH] *** empty log message *** --- docs.sgml | 141 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 104 insertions(+), 37 deletions(-) diff --git a/docs.sgml b/docs.sgml index 800e7ed7..f75d3da3 100644 --- a/docs.sgml +++ b/docs.sgml @@ -330,6 +330,15 @@ require_once(SMARTY_DIR."Smarty.class.php"); the web server document root. + + $plugins_dir + + This is the directory where Smarty will look for the plugins that + it needs. The directory must be relative to the directory where + Smarty itself is installed. Default is "plugins". There can be + only one plugins directory. + + $debugging @@ -1561,51 +1570,51 @@ $smarty->display("file:F:/path/to/my/templates/menu.tpl"); // put these function somewhere in your application function db_get_template ($tpl_name, &tpl_source, &$smarty_obj) { - // do database call here to fetch your template, - // populating $tpl_source - $sql = new SQL; - $sql->query("select tpl_source - from my_table - where tpl_name='$tpl_name'"); - if ($sql->num_rows) { - $tpl_source = $sql->record['tpl_source']; - return true; - } else { - return false; - } + // do database call here to fetch your template, + // populating $tpl_source + $sql = new SQL; + $sql->query("select tpl_source + from my_table + where tpl_name='$tpl_name'"); + if ($sql->num_rows) { + $tpl_source = $sql->record['tpl_source']; + return true; + } else { + return false; + } } function db_get_timestamp($tpl_name, &$tpl_timestamp, &$smarty_obj) { - // do database call here to populate $tpl_timestamp. - $sql = new SQL; - $sql->query("select tpl_timestamp - from my_table + // do database call here to populate $tpl_timestamp. + $sql = new SQL; + $sql->query("select tpl_timestamp + from my_table where tpl_name='$tpl_name'"); - if ($sql->num_rows) { - $tpl_timestamp = $sql->record['tpl_timestamp']; - return true; - } else { - return false; - } + if ($sql->num_rows) { + $tpl_timestamp = $sql->record['tpl_timestamp']; + return true; + } else { + return false; + } } function db_get_secure($tpl_name, &$smarty_obj) { // assume all templates are secure - return true; + return true; } function db_get_trusted($tpl_name, &$smarty_obj) { - // not used + // not used } // register the resource name "db" $smarty->register_resource("db", array("db_get_template", "db_get_timestamp", - "db_get_secure", - "db_get_trusted")); + "db_get_secure", + "db_get_trusted")); // using resource from php script $smarty->display("db:index.tpl"); @@ -6118,17 +6127,75 @@ s m o k e r s a r e p. . . Plugins + Version 2.0 introduced the plugin architecture that is used + for almost all the customizable functionality of Smarty. This includes: + + functions + modifiers + compiler functions + prefilters + postfilters + resources + inserts + + With the exception of resources, backwards compatibility with the old + way of registering handler functions via register_* API is preserved. If + you did not use the API but instead modified the class variables + $custom_funcs, $custom_mods, and + other ones directly, then you will need to adjust your scripts to either + use the API or convert your custom functionality into plugins. + - How Plugins Work - - + How Plugins Work + + Plugins are always loaded on demand. Only the specific modifiers, + functions, resources, etc invoked in the templates or PHP scripts will + be loaded. Moreover, each plugin is loaded only once, even if you have + several different instances of Smarty running within the same request. + + + Pre/post-filters are a bit of a special case. If a pre/post-filter + plugin is found in the plugins directory, it will always be loaded + because these filters are never explicitly mentioned in the template + language. + + + Naming Conventions + + Plugin files and functions must follow a very specific naming + convention in order to be located by Smarty. + + + The plugin files must be named as follows: +
+ type.name.php +
+
+ + type is one of these plugin types: + + function + modifier + compiler + prefilter + postfilter + resource + insert + + + + name should be a valid identifier (letters, + numbers, and underscores only). + +
+ Making Custom Plugins - custom functions + functions @@ -6138,7 +6205,7 @@ s m o k e r s a r e p. . . - modifiers + modifiers @@ -6148,7 +6215,7 @@ s m o k e r s a r e p. . . - compiler functions + compiler functions @@ -6158,7 +6225,7 @@ s m o k e r s a r e p. . . - prefilters + prefilters @@ -6168,7 +6235,7 @@ s m o k e r s a r e p. . . - postfilters + postfilters @@ -6178,17 +6245,17 @@ s m o k e r s a r e p. . . - template resources + template resources -template resource plugin +resource plugin - inserts + inserts