diff --git a/Smarty.class.php b/Smarty.class.php
index 4c281f74..042ba0ed 100644
--- a/Smarty.class.php
+++ b/Smarty.class.php
@@ -163,8 +163,11 @@ class Smarty
function clear_assign($tpl_var)
{
- foreach($tpl_var as $curr_var)
- unset($this->_tpl_vars[$curr_var]);
+ if(is_array($tpl_var))
+ foreach($tpl_var as $curr_var)
+ unset($this->_tpl_vars[$curr_var]);
+ else
+ unset($this->_tpl_vars[$tpl_var]);
}
diff --git a/docs.sgml b/docs.sgml
index c1e495e9..cee156f3 100644
--- a/docs.sgml
+++ b/docs.sgml
@@ -382,9 +382,23 @@ chmod 700 cache
- This is used to assign values to the templates. This is usually
- data gathered from database queries or other sources of data.
+ This is used to assign values to the templates. You can
+ explicitly pass name/value pairs, or associative arrays
+ containing the name/value pairs.
+
+assign
+
+
+// passing name/value pairs
+$smarty->assign("Name","Fred");
+$smarty->assign("Address",$address);
+
+// passing an associative array
+$smarty->assign(array("city" => "Lincoln","state" => "Nebraska"));
+
+
+append
@@ -402,8 +416,23 @@ chmod 700 cache
- This is used to append data to existing variables in the template.
+ This is used to append data to variables in the template. You
+ can explicitly pass name/value pairs, or associative arrays
+ containing the name/value pairs.
+
+append
+
+
+// passing name/value pairs
+$smarty->append("Name","Fred");
+$smarty->append("Address",$address);
+
+// passing an associative array
+$smarty->append(array("city" => "Lincoln","state" => "Nebraska"));
+
+
+clear_assign
@@ -414,8 +443,23 @@ chmod 700 cache
- This clears the value of an assigned variable.
+ This clears the value of an assigned variable. This
+ can be a single value, or an array of values. Array
+ functionality was added to Smarty 1.3.0.
+
+clear_assign
+
+
+// clear a single variable
+$smarty->clear_assign("Name");
+
+// clear multiple variables
+$smarty->clear_assign(array("Name","Address","Zip"));
+
+
+
+clear_all_assign
@@ -428,6 +472,15 @@ chmod 700 cache
This clears the values of all assigned variables.
+
+clear_all_assign
+
+
+// clear all assigned variables
+$smarty->clear_all_assign();
+
+
+register_function
@@ -505,6 +558,19 @@ $smarty->register_modifier("sslash","stripslashes");
caching section for more
information. This was added to Smarty 1.3.0.
+
+clear_cache
+
+
+// clear the cache for a template
+$smarty->clear_cache("index.tpl");
+
+// clear the cache for a particular cache id in an multiple-cache template
+$smarty->clear_cache("index.tpl","CACHEID");
+
+
+
+clear_all_cache
@@ -518,6 +584,16 @@ $smarty->register_modifier("sslash","stripslashes");
This clears the entire template cache. This was added to Smarty
1.3.0.
+
+clear_all_cache
+
+
+// clear the entire cache
+$smarty->clear_all_cache();
+
+
+
+is_cached
@@ -529,8 +605,24 @@ $smarty->register_modifier("sslash","stripslashes");
This returns true if there is a valid cache for this template.
- This was added to Smarty 1.3.0.
+ This only works if caching is set to true. This
+ was added to Smarty 1.3.0.
+
+is_cached
+
+
+$smarty->caching = true;
+
+if(!$smarty->is_cached) {
+ // do database calls, assign vars here
+}
+
+$smarty->display("index.tpl");
+
+
+get_template_vars
@@ -543,6 +635,18 @@ $smarty->register_modifier("sslash","stripslashes");
This gets an array of the currently assigned template vars.
+
+get_template_vars
+
+
+// get all assigned template vars
+$tpl_vars = $smarty->get_template_vars();
+
+// take a look at them
+var_dump($tpl_vars);
+
+
+display
@@ -560,22 +664,6 @@ $smarty->register_modifier("sslash","stripslashes");
See the caching section for
more information.
-
-
- fetch
-
-
- string fetch
- string template
-
-
-
- This returns the template output. Supply a path relative to the
- template directory
-
-
-
- Using Smarty APIExample use of Smarty API
@@ -604,9 +692,54 @@ if(!$smarty->is_cached("index.tpl"))
// display the output
$smarty->display("index.tpl");
+
+
+
+
+ fetch
+
+
+ string fetch
+ string template
+
+
+
+ This returns the template output. Supply a path relative to the
+ template directory
+
+
+Example use of Smarty API
+
+
+include("Smarty.class.php");
+$smarty = new Smarty;
+
+
+// only do db calls if cache doesn't exist
+if(!$smarty->is_cached("index.tpl"))
+{
+
+ // dummy up some data
+ $address = "245 N 50th";
+ $db_data = array(
+ "City" => "Lincoln",
+ "State" => "Nebraska",
+ "Zip" = > "68502"
+ );
+
+ $smarty->assign("Name","Fred");
+ $smarty->assign("Address",$address);
+ $smarty->assign($db_data);
+
+}
+
+// capture the output
+$output = $smarty->fetch("index.tpl");
+
+// do something with $output here
+
+echo $output;
-// alternatively capture the output
-// $output = $smarty->fetch("index.tpl");
diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php
index 4c281f74..042ba0ed 100644
--- a/libs/Smarty.class.php
+++ b/libs/Smarty.class.php
@@ -163,8 +163,11 @@ class Smarty
function clear_assign($tpl_var)
{
- foreach($tpl_var as $curr_var)
- unset($this->_tpl_vars[$curr_var]);
+ if(is_array($tpl_var))
+ foreach($tpl_var as $curr_var)
+ unset($this->_tpl_vars[$curr_var]);
+ else
+ unset($this->_tpl_vars[$tpl_var]);
}