From d539f10a183b5f476354dbcdb0771cccebc4c8a9 Mon Sep 17 00:00:00 2001 From: mohrt Date: Wed, 7 Feb 2001 23:09:32 +0000 Subject: [PATCH] update documentation, remove tests from index file and template --- demo/index.php | 9 -- demo/templates/index.tpl | 6 - docs.sgml | 274 +++++++++++++++++++++++++-------------- index.php | 9 -- templates/index.tpl | 6 - 5 files changed, 178 insertions(+), 126 deletions(-) diff --git a/demo/index.php b/demo/index.php index 62d36665..41b66483 100644 --- a/demo/index.php +++ b/demo/index.php @@ -4,8 +4,6 @@ require("Smarty.class.php"); $smarty = new Smarty; -$smarty->caching = false; - $smarty->assign(now, time()); $smarty->assign("Name","Fred Irving Johnathan Bradley Peppergill"); @@ -19,11 +17,4 @@ $smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => $smarty->display('index.tpl'); -function insert_foo($args) -{ - extract($args); - - return "test $arg1"; -} - ?> diff --git a/demo/templates/index.tpl b/demo/templates/index.tpl index 6087fab7..55b2f2ad 100644 --- a/demo/templates/index.tpl +++ b/demo/templates/index.tpl @@ -46,9 +46,3 @@ testing strip tags {/strip} - -{insert name = foo - arg1=$now arg2=true} - -test: {$now|date_format:"%I:%M %p"} - diff --git a/docs.sgml b/docs.sgml index 181b9639..c1e495e9 100644 --- a/docs.sgml +++ b/docs.sgml @@ -129,19 +129,30 @@ discussed later in this document. - Caching + + Caching - Smarty can cache the output of your generated templates. By default - this is disabled. If you enable caching, Smarty will store a copy - of the generated template output, and use this until the copy - expires, regenerating a new one. If your templates generate the - same content over and over, using the cache will result in huge - performance gains. The default cache expire time is one hour, and - can be configured from the class. The exception to the rule is the - insert tag. Anything - generated by the insert tag is not cached, but run dynamically on - every invocation, even within cached content. + Smarty can cache the output of your generated templates. By default + this is disabled. If you enable + caching, Smarty will store a copy of the generated template + output, and use this until the copy expires, regenerating a new + one. The default cache expire time is one hour, and can be + configured from the class. The exception to the rule is the insert tag. Anything generated by + the insert tag is not cached, but run dynamically on every + invocation, even within cached content. + + TECHNICAL NOTE: Any time you change a template, change values in + config files or change the content that gets displayed in a + template, you must either clear the caches that are affected, or + wait for the cache to expire to see the results of the changes. You + can either do this manually by deleting files from the cache + directory, or programatically with clear_cache or clear_all_cache. + @@ -208,6 +219,37 @@ chmod 700 cache Configuration variables + + $template_dir + + This is the name of the directory where template files are located. + By default this is "./templates". + + + + $compile_dir + + This is the name of the directory where compiled templates are + located. By default this is "./templates_c". This was + added to Smarty version 1.2.1. + + + + $config_dir + + This is the directory used to store config files used in the templates. + Default is "configs". + + + + $global_assign + + This is a list of variables that are always implicitly assigned to the + template engine. This is usually handy for making global variables or server + variables available to the template without having to manually assign them to + the template every time. + + $compile_check @@ -249,6 +291,14 @@ chmod 700 cache undesireable results. This was added to Smarty 1.3.0. + + $cache_dir + + This is the name of the directory where template caches are + located. By default this is "./cache". This was + added to Smarty version 1.3.0. + + $cache_lifetime @@ -260,40 +310,7 @@ chmod 700 cache added to Smarty 1.3.0. - - $template_dir - - This is the name of the directory where template files are located. - By default this is "./templates". - - - - $compile_dir - - This is the name of the directory where compiled templates are - located. By default this is "./templates_c". This was - added to Smarty version 1.2.1. - - - - $cache_dir - - This is the name of the directory where template caches are - located. By default this is "./cache". This was - added to Smarty version 1.3.0. - - - - $compile_dir_ext - - This is the extension used for the name of the directory where - compiled templates are located. By default this is "_c". - Therefore if your template directory is named "templates", then - the compiled templates directory will be named "templates_c". - NOTE: this was removed from Smarty version 1.2.1. - - - + $tpl_file_ext This is the extention used for template files. By default this @@ -301,7 +318,7 @@ chmod 700 cache ignored. - + $allow_php Whether or not to allow PHP code in the templates. If set to @@ -312,26 +329,19 @@ chmod 700 cache is "false". - + $left_delimiter This is the left delimiter used by the template language. Default is "{". - + $right_delimiter This is the right delimiter used by the template language. Default is "}". - - $config_dir - - This is the directory used to store config files used in the templates. - Default is "configs". - - - + $custom_funcs This is a mapping of the names of - + $custom_mods This is a mapping of the names of variable @@ -347,15 +357,6 @@ chmod 700 cache the names of functions in PHP. These are usually kept in Smarty.addons.php. - - $global_assign - - This is a list of variables that are always implicitly assigned to the - template engine. This is usually handy for making global variables or server - variables available to the template without having to manually assign them to - the template every time. - - @@ -365,7 +366,7 @@ chmod 700 cache Smarty API Functions - + assign @@ -385,7 +386,7 @@ chmod 700 cache data gathered from database queries or other sources of data. - + append @@ -404,7 +405,7 @@ chmod 700 cache This is used to append data to existing variables in the template. - + clear_assign @@ -416,7 +417,7 @@ chmod 700 cache This clears the value of an assigned variable. - + clear_all_assign @@ -428,6 +429,83 @@ chmod 700 cache This clears the values of all assigned variables. + + register_function + + + void register_function + string funcname + string funcimpl + + + + Use this to dynamically register functions with Smarty. Pass in + the Smarty function name, followed by the actual function name + that it is mapped to. + + +register_function + + +$smarty->register_function("date_now","print_current_date"); + +function print_current_date ($params) { + extract($params); + if(empty($format)) + $format="%b %e, %Y"; + echo strftime($format,time()); +} + +// now you can use this in Smarty to print the current date: {date_now} +// or, {date_now format="%Y/%m/%d"} to format it. + + + + + + register_modifier + + + void register_modifier + string modname + string funcimpl + + + + Use this to dynamically register modifiers with Smarty. Pass in + the Smarty modifier name, followed by the actual function name + that it is mapped to. + + +register_modifier + + +// let's map PHP's stripslashes function to a Smarty modifier. + +$smarty->register_modifier("sslash","stripslashes"); + +// now you can use {$var|sslash} to strip slashes from variables + + + + + + clear_cache + + + void clear_cache + string template + string cache id + + + + This clears the cache. For the specified template. If you have + multiple caches for this template, you can clear a specific + cache by supplying the cache id as the second parameter. See the + caching section for more + information. This was added to Smarty 1.3.0. + + clear_all_cache @@ -451,12 +529,10 @@ chmod 700 cache This returns true if there is a valid cache for this template. - Use this to skip process-intensive tasks that aren't necessary - when a cached version of the template is available. This was - added to Smarty 1.3.0. + This was added to Smarty 1.3.0. - + get_template_vars @@ -468,20 +544,24 @@ chmod 700 cache This gets an array of the currently assigned template vars. - + display void display string template + string cache id This displays the template. Supply a path relative to the - template directory + template directory. + As an optional second parameter, you can pass a cache id. + See the caching section for + more information. - + fetch @@ -491,13 +571,13 @@ chmod 700 cache This returns the template output. Supply a path relative to the - template directory + template directory Using Smarty API - - Example use of Smarty API + +Example use of Smarty API include("Smarty.class.php"); @@ -528,7 +608,7 @@ $smarty->display("index.tpl"); // alternatively capture the output // $output = $smarty->fetch("index.tpl"); - + @@ -943,12 +1023,12 @@ Intro = """This is a value that spans more and display the returned results in place of the insert tag. - A note on caching: If you have caching turned on, insert tags - will not be cached. They will run dynamically every time the page - is created, even within cached pages. This works good for things - like banners, polls, live weather, search results, user feedback - areas, etc. + TECHNICAL NOTE: It is possible to have portions of the template not + cached. If you have caching + turned on, insert tags will not be cached. They will run + dynamically every time the page is created, even within cached + pages. This works good for things like banners, polls, live + weather, search results, user feedback areas, etc. @@ -2502,26 +2582,28 @@ function makeTimeStamp($year="",$month="",$day="") CREDITS - Monte Ohrt <monte@ispi.net>: Idea of compiling into PHP scripts, - initial implementation, documentation. + Monte Ohrt <monte@ispi.net>: Concepted compiling templates into PHP + scripts, wrote initial "proof of concept" implementation, and maintains + documentation. - Andrei Zmievski <andrei@ispi.net>: Rewrote parser from scratch, added - custom modifier functionality, and much more. + Andrei Zmievski <andrei@ispi.net>: Rewrote parser from scratch and + added other features too numerous to mention. - Anne Holz <anne@ispi.net>: Contributed several ideas for formatting features. + Anne Holz <anne@ispi.net>: Many of Smarty's formatting features were + a direct result of needs from her department. Frank Kromann <fmk@php.net>: Idea of custom function ability. - A special thanks goes to all the people that have contributed other - templating solutions to the PHP community which we learned a lot from. + A special thanks goes to the people that have contributed other templating + solutions to the PHP community which we learned a lot from. - A special thanks goes to all the members of the php-template mailing list, - who shared and brought many ideas to the table. + A special thanks goes to the members of the php-template mailing list and + the smarty mailing list, whom shared and brought many ideas to the table. Rasmus Lerdorf <rasmus@php.net>: For starting what eventually became diff --git a/index.php b/index.php index 62d36665..41b66483 100644 --- a/index.php +++ b/index.php @@ -4,8 +4,6 @@ require("Smarty.class.php"); $smarty = new Smarty; -$smarty->caching = false; - $smarty->assign(now, time()); $smarty->assign("Name","Fred Irving Johnathan Bradley Peppergill"); @@ -19,11 +17,4 @@ $smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => $smarty->display('index.tpl'); -function insert_foo($args) -{ - extract($args); - - return "test $arg1"; -} - ?> diff --git a/templates/index.tpl b/templates/index.tpl index 6087fab7..55b2f2ad 100644 --- a/templates/index.tpl +++ b/templates/index.tpl @@ -46,9 +46,3 @@ testing strip tags {/strip} - -{insert name = foo - arg1=$now arg2=true} - -test: {$now|date_format:"%I:%M %p"} -