diff --git a/NEWS b/NEWS index 1b4bf03f..3bae0aa5 100644 --- a/NEWS +++ b/NEWS @@ -1,12 +1,13 @@ + - numerous documentation updates. (Monte) + - added ENT_QUOTES to escapement of html (Monte, Sam Beckwith) - implemented access to request variables via auto-assigned $smarty template variable. (Andrei) - fixed a bug with parsing function arguments inside {if} tags if a comma was present. (Andrei) - updated debug console with config file vars. (Monte) - - numerous documentation updates. (Monte) - - added SMARTY_DIR constant which indicating location of Smarty files. + - added SMARTY_DIR constant as an alternative to relying on include_path (Monte) - - added popup_init and popup functions. (Monte) + - added popup_init and popup functions, (requires overlib.js) (Monte) - updated debug console with config file vars. (Monte) - added debugging url control. (Monte) - added 'quotes' type to escape modifier. (Monte, Mike Krus) diff --git a/Smarty.addons.php b/Smarty.addons.php index a64cb0a0..6a949427 100644 --- a/Smarty.addons.php +++ b/Smarty.addons.php @@ -83,7 +83,7 @@ function smarty_mod_escape($string, $esc_type = 'html') { switch ($esc_type) { case 'html': - return htmlspecialchars($string); + return htmlspecialchars($string, ENT_QUOTES); case 'url': return urlencode($string); diff --git a/Smarty_Compiler.class.php b/Smarty_Compiler.class.php index f26f8755..798c79db 100644 --- a/Smarty_Compiler.class.php +++ b/Smarty_Compiler.class.php @@ -514,7 +514,6 @@ class Smarty_Compiler extends Smarty { )/x', $tag_args, $match); $tokens = $match[0]; - var_dump($tokens); $this->_parse_vars_props($tokens); $is_arg_stack = array(); diff --git a/demo/templates/header.tpl b/demo/templates/header.tpl index 24d26fdf..e5b68395 100644 --- a/demo/templates/header.tpl +++ b/demo/templates/header.tpl @@ -1,7 +1,6 @@ -{tooltip_init} -{tooltip_element id="help" width="200" text="This is an example of a tooltip. Tooltips are handy for context sensitive information."} +{popup_init} {$title} - {$Name} diff --git a/demo/templates/index.tpl b/demo/templates/index.tpl index d6dc7b4d..4851797d 100644 --- a/demo/templates/index.tpl +++ b/demo/templates/index.tpl @@ -9,14 +9,21 @@ Title: {#title#|capitalize} {if #bold#}{/if} -Tooltip example: Move your mouse over the Help link to see a tooltip pop-up. +Tooltip example: Move your mouse over the Help link to see an example of a tooltip using Smarty's popup function. -the value of $SCRIPT_NAME is {$SCRIPT_NAME} +The value of global assigned variable $SCRIPT_NAME is {$SCRIPT_NAME} -{* A simple variable test. print $Name in uppercase *} -hello, my name is {$Name} +Example of accessing server environment variable SERVER_NAME: {$smarty.server.SERVER_NAME} + +The value of {ldelim}$Name{rdelim} is {$Name} + +variable modifier example of {ldelim}$Name|upper{rdelim} + +{$Name|upper} + + +An example of a section loop: -My interests are: {section name=outer loop=$FirstName} {if %outer.index% is odd by 2} {%outer.rownum%} . {$FirstName[outer]} {$LastName[outer]} @@ -27,7 +34,8 @@ My interests are: none {/section} -testing section looped key values
+An example of section looped key values: + {section name=sec1 loop=$contacts} phone: {$contacts[sec1].phone}
fax: {$contacts[sec1].fax}
diff --git a/docs.sgml b/docs.sgml index 6072d97b..b3c1aa85 100644 --- a/docs.sgml +++ b/docs.sgml @@ -249,6 +249,17 @@ chmod 700 cache used to locate the files. If defined, the path must end with a slash. + +SMARTY_DIR + + +// set path to Smarty directory +define("SMARTY_DIR","/usr/local/lib/php/Smarty/"); + +require_once(SMARTY_DIR."Smarty.class.php"); + + + @@ -1400,18 +1411,12 @@ $smarty->display("index.tpl"); between the tags, and displays the appropriate output in place of them. - Variables + Variables assigned from PHP - There are three basic types of variables in Smarty, each with their - own unique syntax. + Variables that are assigned from PHP are referenced by preceding + them with a dollar sign ($) and enclosing the variable in delimiters + like so: $varname - - Variables assigned from PHP - - Variables that are assigned from PHP are referenced by preceding - them with a dollar sign ($) and enclosing the variable in delimiters - like so: $varname - displaying assigned variables @@ -1428,15 +1433,14 @@ Hello Doug, glad to see you could make it. Your last login was on January 11th, 2001. - - - - Associative arrays - - You can also reference associative array variables that are - assigned from PHP by specifying the key after the '.' (period) - symbol. - + + + Associative arrays + + You can also reference associative array variables that are + assigned from PHP by specifying the key after the '.' (period) + symbol. + displaying assigned associative array variables @@ -1458,14 +1462,13 @@ zaphod@slartibartfast.com<br> - - - - Objects - - Properties of objects assigned from PHP can be referenced - by specifying the property name after the '->' symbol. - + + + Objects + + Properties of objects assigned from PHP can be referenced + by specifying the property name after the '->' symbol. + displaying object properties @@ -1480,15 +1483,15 @@ email: zaphod@slartibartfast.com<br> - + - - Variables passed from config files - - Variables that are passed in from config files are displayed by enclosing - them with hash marks (#) and enclosing the variable in delimiters - like so: {#varname#} - + + Variables passed from config files + + Variables that are passed in from config files are displayed by enclosing + them with hash marks (#) and enclosing the variable in delimiters + like so: {#varname#} + @@ -1499,33 +1502,71 @@ email: zaphod@slartibartfast.com<br> <title>{#pageTitle#}</title> <body bgcolor="{#bodyBgColor#}"> <table border="{#tableBorderSize#}" bgcolor="{#tableBgColor#}"> - <tr bgcolor="{#rowBgColor#}"> - <td>First</td> - <td>Last</td> - <td>Address</td> - </tr> +<tr bgcolor="{#rowBgColor#}"> + <td>First</td> + <td>Last</td> + <td>Address</td> +</tr> </table> </body> </html> - - Config file variables cannot be displayed until - after they are loaded in from a config file. This procedure is - explained later in this document under - config_load. - - - - Variables internal to template - - Variables that are internal to the templates are displayed by enclosing - them with percent signs (%) and enclosing the variable in delimiters - like so: {%varname%} So far, section properties are the only internal - variables used in Smarty, which can be found later in this document under - section. - - + + Config file variables cannot be displayed until + after they are loaded in from a config file. This procedure is + explained later in this document under + config_load. + + + + Variables internal to template + + Variables that are internal to the templates are displayed by enclosing + them with percent signs (%) and enclosing the variable in delimiters + like so: {%varname%} So far, section properties are the only internal + variables used in Smarty, which can be found later in this document under + section. + + + + Request Variables + + You can access request variables in Smarty via the special variable + {$smarty}. You can access get, post, cookies, server, env and + session variables with the syntax in the following examples. + + + Request variable access was added to Smarty 1.4.4. + + + +displaying request variables + + +{* display the variable "page" given in the URL, or from a form using the GET method *} +{$smarty.get.page} + +{* display the variable "page" from a form using the POST method *} +{$smarty.post.page} + +{* display the value of the cookie "username" *} +{$smarty.cookies.username} + +{* display the server variable "SERVER_NAME" *} +{$smarty.server.SERVER_NAME} + +{* display the system environment variable "PATH" *} +{$smarty.env.PATH} + +{* display the php session variable "id" *} +{$smarty.session.id} + +{* display the variable "username" from merged get/post/cookies/server/env *} +{$smarty.request.username} + + + Functions @@ -2402,23 +2443,24 @@ e-mail: jane@mydomain.com<p> These are indicated by percent signs around the variable name, like so: %sectionname.varname% - - index - - index is used to display the current loop index, starting with zero - (or the start attribute if given), and incrementing by one (or by - the step attribute if given.) - - - TECHNICAL NOTE: If the step and start section properties are not - modified, then this works the same as the iteration section - property. - + + + index + + index is used to display the current loop index, starting with zero + (or the start attribute if given), and incrementing by one (or by + the step attribute if given.) + + + TECHNICAL NOTE: If the step and start section properties are not + modified, then this works the same as the iteration section + property. + section property index {section name=customer loop=$custid} - {%customer.index%} id: {$custid[customer]}<br> +{%customer.index%} id: {$custid[customer]}<br> {/section} @@ -2430,90 +2472,90 @@ OUTPUT: - - - index_prev - - index_prev is used to display the previous loop index. - on the first loop, this is set to -1. - + + + index_prev + + index_prev is used to display the previous loop index. + on the first loop, this is set to -1. + section property index_prev {section name=customer loop=$custid} - {%customer.index%} id: {$custid[customer]}<br> - {* FYI, $custid[customer.index] and $custid[customer] are identical in meaning *} - {if $custid[customer.index_prev] ne $custid[customer.index]} - The customer id changed<br> - {/if} +{%customer.index%} id: {$custid[customer]}<br> +{* FYI, $custid[customer.index] and $custid[customer] are identical in meaning *} +{if $custid[customer.index_prev] ne $custid[customer.index]} + The customer id changed<br> +{/if} {/section} OUTPUT: 0 id: 1000<br> - The customer id changed<br> + The customer id changed<br> 1 id: 1001<br> - The customer id changed<br> + The customer id changed<br> 2 id: 1002<br> - The customer id changed<br> + The customer id changed<br> - - - index_next - - index_next is used to display the next loop index. On the last - loop, this is still one more than the current index (respecting the - setting of the step attribute, if given.) - + + + index_next + + index_next is used to display the next loop index. On the last + loop, this is still one more than the current index (respecting the + setting of the step attribute, if given.) + section property index_next {section name=customer loop=$custid} - {%customer.index%} id: {$custid[customer]}<br> - {* FYI, $custid[customer.index] and $custid[customer] are identical in meaning *} - {if $custid[customer.index_next] ne $custid[customer.index]} - The customer id will change<br> - {/if} +{%customer.index%} id: {$custid[customer]}<br> +{* FYI, $custid[customer.index] and $custid[customer] are identical in meaning *} +{if $custid[customer.index_next] ne $custid[customer.index]} + The customer id will change<br> +{/if} {/section} OUTPUT: 0 id: 1000<br> - The customer id will change<br> + The customer id will change<br> 1 id: 1001<br> - The customer id will change<br> + The customer id will change<br> 2 id: 1002<br> - The customer id will change<br> + The customer id will change<br> - - - iteration - - iteration is used to display the current loop iteration. - - - NOTE: This is not affected by the section properties start, step and - max, unlike the index property. - - - This was added to Smarty 1.4.4. - + + + iteration + + iteration is used to display the current loop iteration. + + + NOTE: This is not affected by the section properties start, step and + max, unlike the index property. + + + This was added to Smarty 1.4.4. + section property iteration {section name=customer loop=$custid start=5 step=2} - current loop iteration: {%customer.iteration%}<br> - {%customer.index%} id: {$custid[customer]}<br> - {* FYI, $custid[customer.index] and $custid[customer] are identical in meaning *} - {if $custid[customer.index_next] ne $custid[customer.index]} - The customer id will change<br> - {/if} +current loop iteration: {%customer.iteration%}<br> +{%customer.index%} id: {$custid[customer]}<br> +{* FYI, $custid[customer.index] and $custid[customer] are identical in meaning *} +{if $custid[customer.index_next] ne $custid[customer.index]} + The customer id will change<br> +{/if} {/section} @@ -2521,96 +2563,96 @@ OUTPUT: current loop iteration: 1 5 id: 1000<br> - The customer id will change<br> + The customer id will change<br> current loop iteration: 2 7 id: 1001<br> - The customer id will change<br> + The customer id will change<br> current loop iteration: 3 9 id: 1002<br> - The customer id will change<br> + The customer id will change<br> - - - first - - first is set to true if the current section iteration is the first - one. - + + + first + + first is set to true if the current section iteration is the first + one. + section property first {section name=customer loop=$custid} - {if %customer.first%} - <table> - {/if} +{if %customer.first%} + <table> +{/if} - <tr><td>{%customer.index%} id: - {$custid[customer]}</td></tr> +<tr><td>{%customer.index%} id: + {$custid[customer]}</td></tr> - {if %customer.last%} - </table> - {/if} +{if %customer.last%} + </table> +{/if} {/section} OUTPUT: <table> - <tr><td>0 id: 1000</td></tr> - <tr><td>1 id: 1001</td></tr> - <tr><td>2 id: 1002</td></tr> +<tr><td>0 id: 1000</td></tr> +<tr><td>1 id: 1001</td></tr> +<tr><td>2 id: 1002</td></tr> </table> - - - last - - last is set to true if the current section iteration is the last - one. - + + + last + + last is set to true if the current section iteration is the last + one. + section property last {section name=customer loop=$custid} - {if %customer.first%} - <table> - {/if} +{if %customer.first%} + <table> +{/if} - <tr><td>{%customer.index%} id: - {$custid[customer]}</td></tr> +<tr><td>{%customer.index%} id: + {$custid[customer]}</td></tr> - {if %customer.last%} - </table> - {/if} +{if %customer.last%} + </table> +{/if} {/section} OUTPUT: <table> - <tr><td>0 id: 1000</td></tr> - <tr><td>1 id: 1001</td></tr> - <tr><td>2 id: 1002</td></tr> +<tr><td>0 id: 1000</td></tr> +<tr><td>1 id: 1001</td></tr> +<tr><td>2 id: 1002</td></tr> </table> - - - rownum - - rownum is used to display the current loop iteration, - starting with one. - + + + rownum + + rownum is used to display the current loop iteration, + starting with one. + section property rownum {section name=customer loop=$custid} - {%customer.rownum%} id: {$custid[customer]}<br> +{%customer.rownum%} id: {$custid[customer]}<br> {/section} @@ -2622,18 +2664,18 @@ OUTPUT: - - - loop - - loop is used to display the last index number that this section - looped. This can be used inside or after the section. - + + + loop + + loop is used to display the last index number that this section + looped. This can be used inside or after the section. + section property index {section name=customer loop=$custid} - {%customer.index%} id: {$custid[customer]}<br> +{%customer.index%} id: {$custid[customer]}<br> {/section} There were {%customer.loop%} customers shown above. @@ -2648,28 +2690,28 @@ There were 3 customers shown above. - - - show - - show is used as a parameter to section. - show is a boolean value, true or false. If - false, the section will not be displayed. If there is a sectionelse - present, that will be alternately displayed. - + + + show + + show is used as a parameter to section. + show is a boolean value, true or false. If + false, the section will not be displayed. If there is a sectionelse + present, that will be alternately displayed. + section attribute show {* $show_customer_info may have been passed from the PHP - application, to regulate whether or not this section shows *} +application, to regulate whether or not this section shows *} {section name=customer loop=$custid show=$show_customer_info} - {%customer.rownum%} id: {$custid[customer]}<br> +{%customer.rownum%} id: {$custid[customer]}<br> {/section} {if %customer.show%} - the section was shown. +the section was shown. {else} - the section was not shown. +the section was not shown. {/if} @@ -2683,21 +2725,21 @@ the section was shown. - - - total - - total is used to display the number of iterations that this section - will loop. This can be used inside or after the section. - - - This was added to Smarty 1.4.4. - + + + total + + total is used to display the number of iterations that this section + will loop. This can be used inside or after the section. + + + This was added to Smarty 1.4.4. + section property total {section name=customer loop=$custid step=2} - {%customer.index%} id: {$custid[customer]}<br> +{%customer.index%} id: {$custid[customer]}<br> {/section} There were {%customer.total%} customers shown above. @@ -2712,7 +2754,6 @@ There were 3 customers shown above. - strip diff --git a/libs/Smarty_Compiler.class.php b/libs/Smarty_Compiler.class.php index f26f8755..798c79db 100644 --- a/libs/Smarty_Compiler.class.php +++ b/libs/Smarty_Compiler.class.php @@ -514,7 +514,6 @@ class Smarty_Compiler extends Smarty { )/x', $tag_args, $match); $tokens = $match[0]; - var_dump($tokens); $this->_parse_vars_props($tokens); $is_arg_stack = array(); diff --git a/templates/header.tpl b/templates/header.tpl index 24d26fdf..e5b68395 100644 --- a/templates/header.tpl +++ b/templates/header.tpl @@ -1,7 +1,6 @@ -{tooltip_init} -{tooltip_element id="help" width="200" text="This is an example of a tooltip. Tooltips are handy for context sensitive information."} +{popup_init} {$title} - {$Name} diff --git a/templates/index.tpl b/templates/index.tpl index d6dc7b4d..4851797d 100644 --- a/templates/index.tpl +++ b/templates/index.tpl @@ -9,14 +9,21 @@ Title: {#title#|capitalize} {if #bold#}{/if} -Tooltip example: Move your mouse over the Help link to see a tooltip pop-up. +Tooltip example: Move your mouse over the Help link to see an example of a tooltip using Smarty's popup function. -the value of $SCRIPT_NAME is {$SCRIPT_NAME} +The value of global assigned variable $SCRIPT_NAME is {$SCRIPT_NAME} -{* A simple variable test. print $Name in uppercase *} -hello, my name is {$Name} +Example of accessing server environment variable SERVER_NAME: {$smarty.server.SERVER_NAME} + +The value of {ldelim}$Name{rdelim} is {$Name} + +variable modifier example of {ldelim}$Name|upper{rdelim} + +{$Name|upper} + + +An example of a section loop: -My interests are: {section name=outer loop=$FirstName} {if %outer.index% is odd by 2} {%outer.rownum%} . {$FirstName[outer]} {$LastName[outer]} @@ -27,7 +34,8 @@ My interests are: none {/section} -testing section looped key values
+An example of section looped key values: + {section name=sec1 loop=$contacts} phone: {$contacts[sec1].phone}
fax: {$contacts[sec1].fax}