diff --git a/docs/en/designers/language-builtin-functions/language-function-foreach.xml b/docs/en/designers/language-builtin-functions/language-function-foreach.xml index bb63ed75..f64c6d61 100644 --- a/docs/en/designers/language-builtin-functions/language-function-foreach.xml +++ b/docs/en/designers/language-builtin-functions/language-function-foreach.xml @@ -1,194 +1,202 @@ - - foreach,foreachelse - - - - - - - - - - Attribute Name - Type - Required - Default - Description - - - - - from - array - Yes - n/a - The array you are looping through - - - item - string - Yes - n/a - The name of the variable that is the current - element - - - key - string - No - n/a - The name of the variable that is the current key - - - name - string - No - n/a - The name of the foreach loop for accessing - foreach properties - - - - - - foreach loops are an alternative to - section loops. foreach is - used to loop over a single associative array. The syntax for - foreach is much easier than - section, but as a tradeoff it can only be used - for a single array. foreach tags must be - paired with /foreach tags. Required parameters - are from and item. The - name of the foreach loop can be anything you like, made up of - letters, numbers and underscores. foreach - loops can be nested, and the nested foreach names must be unique - from each other. The from variable (usually an - array of values) determines the number of times - foreach will loop. - foreachelse is executed when there are no - values in the from variable. - - -foreach - + + foreach,foreachelse + + + + + + + + + + Attribute Name + Type + Required + Default + Description + + + + + from + array + Yes + n/a + The array you are looping through + + + item + string + Yes + n/a + The name of the variable that is the current + element + + + key + string + No + n/a + The name of the variable that is the current key + + + name + string + No + n/a + The name of the foreach loop for accessing + foreach properties + + + + + + foreach loops are an alternative to + section loops. foreach is + used to loop over a single associative array. The syntax for + foreach is much easier than + section, but as a tradeoff it can only be used + for a single array. foreach tags must be + paired with /foreach tags. Required parameters + are from and item. The + name of the foreach loop can be anything you like, made up of + letters, numbers and underscores. foreach + loops can be nested, and the nested foreach names must be unique + from each other. The from variable (usually an + array of values) determines the number of times + foreach will loop. + foreachelse is executed when there are no + values in the from variable. + + + foreach + + + {/foreach} +]]> + + + The above example will output: + + + + id: 1001
+ id: 1002
+]]> +
+
-OUTPUT: + + foreach key + + - + assignment looks like this: - -foreach key - -{* The key contains the key for each looped value + $smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"), + array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234"))); -assignment looks like this: + *} -$smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"), - array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234"))); + {foreach name=outer item=contact from=$contacts} + {foreach key=key item=item from=$contact} + {$key}: {$item}
+ {/foreach} + {/foreach} + ]]> +
+ + The above example will output: + + + + fax: 2
+ cell: 3
+ phone: 555-4444
+ fax: 555-3333
+ cell: 760-1234
+]]> +
+
-*} - -{foreach name=outer item=contact from=$contacts} - {foreach key=key item=item from=$contact} - {$key}: {$item}<br> - {/foreach} -{/foreach} - -OUTPUT: - -phone: 1<br> -fax: 2<br> -cell: 3<br> -phone: 555-4444<br> -fax: 555-3333<br> -cell: 760-1234<br>
-
- - - Foreach-loops also have their own variables that handle foreach properties. - These are indicated like so: {$smarty.foreach.foreachname.varname} with - foreachname being the name specified as the name - attribute of foreach - - - - - iteration - - iteration is used to display the current loop iteration. - - - Iteration always starts with 1 and is incremented by one - one each iteration. - - - - - first - - first is set to true if the current foreach iteration is the first - one. - - - - - last - - last is set to true if the current foreach iteration is the last - one. - - - - - show - - show is used as a parameter to foreach. - show is a boolean value, true or false. If - false, the foreach will not be displayed. If there is a foreachelse - present, that will be alternately displayed. - - - - - total - - total is used to display the number of iterations that this foreach - will loop. This can be used inside or after the foreach. - - + + Foreach-loops also have their own variables that handle foreach properties. + These are indicated like so: {$smarty.foreach.foreachname.varname} with + foreachname being the name specified as the name + attribute of foreach + + + iteration + + iteration is used to display the current loop iteration. + + + Iteration always starts with 1 and is incremented by one + one each iteration. + + + + first + + first is set to true if the current foreach iteration is the first + one. + + + + last + + last is set to true if the current foreach iteration is the last + one. + + + + show + + show is used as a parameter to foreach. + show is a boolean value, true or false. If + false, the foreach will not be displayed. If there is a foreachelse + present, that will be alternately displayed. + + + + total + + total is used to display the number of iterations that this foreach + will loop. This can be used inside or after the foreach. + +
\ No newline at end of file diff --git a/docs/en/designers/language-builtin-functions/language-function-if.xml b/docs/en/designers/language-builtin-functions/language-function-if.xml index 079f14fa..a322de2c 100644 --- a/docs/en/designers/language-builtin-functions/language-function-if.xml +++ b/docs/en/designers/language-builtin-functions/language-function-if.xml @@ -1,224 +1,227 @@ - - if,elseif,else - - {if} statements in Smarty have much the same flexibility as PHP if - statements, with a few added features for the template engine. - Every {if} must be paired with an - {/if}. {else} and - {elseif} are also permitted. All PHP conditionals - are recognized, such as ||, or, - &&, and, etc. - + + if,elseif,else + + {if} statements in Smarty have much the same flexibility as PHP if + statements, with a few added features for the template engine. + Every {if} must be paired with an + {/if}. {else} and + {elseif} are also permitted. All PHP conditionals + are recognized, such as ||, or, + &&, and, etc. + - - The following is a list of recognized qualifiers, which must be - separated from surrounding elements by spaces. Note that items listed - in [brackets] are optional. PHP equivalents are shown where applicable. - + + The following is a list of recognized qualifiers, which must be + separated from surrounding elements by spaces. Note that items listed + in [brackets] are optional. PHP equivalents are shown where applicable. + - - - - - - - - - - Qualifier - Alternates - Syntax Example - Meaning - PHP Equivalent - - - - - == - eq - $a eq $b - equals - == - - - != - ne, neq - $a neq $b - not equals - != - - - > - gt - $a gt $b - greater than - > - - - < - lt - $a lt $b - less than - < - - - >= - gte, ge - $a ge $b - greater than or equal - >= - - - <= - lte, le - $a le $b - less than or equal - <= - - - === - - $a === 0 - check for identity - === - - - ! - not - not $a - negation (unary) - ! - - - % - mod - $a mod $b - modulous - % - - - is [not] div by - - $a is not div by 4 - divisible by - $a % $b == 0 - - - is [not] even - - $a is not even - [not] an even number (unary) - $a % 2 == 0 - - - is [not] even by - - $a is not even by $b - grouping level [not] even - ($a / $b) % 2 == 0 - - - is [not] odd - - $a is not odd - [not] an odd number (unary) - $a % 2 != 0 - - - is [not] odd by - - $a is not odd by $b - [not] an odd grouping - ($a / $b) % 2 != 0 - - - - - -if statements - -{if $name eq "Fred"} - Welcome Sir. -{elseif $name eq "Wilma"} - Welcome Ma'am. -{else} - Welcome, whatever you are. -{/if} + + + + + + + + + + Qualifier + Alternates + Syntax Example + Meaning + PHP Equivalent + + + + + == + eq + $a eq $b + equals + == + + + != + ne, neq + $a neq $b + not equals + != + + + > + gt + $a gt $b + greater than + > + + + < + lt + $a lt $b + less than + < + + + >= + gte, ge + $a ge $b + greater than or equal + >= + + + <= + lte, le + $a le $b + less than or equal + <= + + + === + + $a === 0 + check for identity + === + + + ! + not + not $a + negation (unary) + ! + + + % + mod + $a mod $b + modulous + % + + + is [not] div by + + $a is not div by 4 + divisible by + $a % $b == 0 + + + is [not] even + + $a is not even + [not] an even number (unary) + $a % 2 == 0 + + + is [not] even by + + $a is not even by $b + grouping level [not] even + ($a / $b) % 2 == 0 + + + is [not] odd + + $a is not odd + [not] an odd number (unary) + $a % 2 != 0 + + + is [not] odd by + + $a is not odd by $b + [not] an odd grouping + ($a / $b) % 2 != 0 + + + + + + if statements + += #minVolAmt#} - ... -{/if} + {* parenthesis are allowed *} + {if ( $amount < 0 or $amount > 1000 ) and $volume >= #minVolAmt#} + ... + {/if} -{* you can also embed php function calls *} -{if count($var) gt 0} - ... -{/if} + {* you can also embed php function calls *} + {if count($var) gt 0} + ... + {/if} -{* test if values are even or odd *} -{if $var is even} - ... -{/if} -{if $var is odd} - ... -{/if} -{if $var is not odd} - ... -{/if} + {* test if values are even or odd *} + {if $var is even} + ... + {/if} + {if $var is odd} + ... + {/if} + {if $var is not odd} + ... + {/if} -{* test if var is divisible by 4 *} -{if $var is div by 4} - ... -{/if} + {* test if var is divisible by 4 *} + {if $var is div by 4} + ... + {/if} -{* test if var is even, grouped by two. i.e., -0=even, 1=even, 2=odd, 3=odd, 4=even, 5=even, etc. *} -{if $var is even by 2} - ... -{/if} + {* test if var is even, grouped by two. i.e., + 0=even, 1=even, 2=odd, 3=odd, 4=even, 5=even, etc. *} + {if $var is even by 2} + ... + {/if} -{* 0=even, 1=even, 2=even, 3=odd, 4=odd, 5=odd, etc. *} -{if $var is even by 3} - ... -{/if} - + {* 0=even, 1=even, 2=even, 3=odd, 4=odd, 5=odd, etc. *} + {if $var is even by 3} + ... + {/if} +]]> + + \ No newline at end of file diff --git a/docs/en/designers/language-builtin-functions/language-function-include-php.xml b/docs/en/designers/language-builtin-functions/language-function-include-php.xml index bcc583bd..e7982bd0 100644 --- a/docs/en/designers/language-builtin-functions/language-function-include-php.xml +++ b/docs/en/designers/language-builtin-functions/language-function-include-php.xml @@ -1,141 +1,145 @@ - - include_php - - - - - - - - - - Attribute Name - Type - Required - Default - Description - - - - - file - string - Yes - n/a - The name of the php file to include - - - once - boolean - No - true - whether or not to include the php file more than - once if included multiple times - - - assign - string - No - n/a - The name of the variable that the output of - include_php will be assigned to - - - - - - Technical Note - - include_php is pretty much deprecated from Smarty, you can - accomplish the same functionality via a custom template function. - The only reason to use include_php is if you really have a need to - quarantine the php function away from the plugin directory or your - application code. See the componentized template - example for details. - - - - include_php tags are used to include a php script in your template. - If security is enabled, then the php script must be located in the - $trusted_dir path. The include_php tag must have the attribute - "file", which contains the path to the included php file, either - relative to $trusted_dir, or an absolute path. - - - include_php is a nice way to handle componentized templates, and - keep PHP code separate from the template files. Lets say you have a - template that shows your site navigation, which is pulled - dynamically from a database. You can keep your PHP logic that grabs - database content in a separate directory, and include it at the top - of the template. Now you can include this template anywhere without - worrying if the database information was assigned by the application - before hand. - - - By default, php files are only included once even if called - multiple times in the template. You can specify that it should be - included every time with the once attribute. - Setting once to false will include the php script each time it is - included in the template. - - - You can optionally pass the assign attribute, - which will specify a template variable name that the output of - include_php will be assigned to instead of - displayed. - - - The smarty object is available as $this within the PHP script that you - include. - - -function include_php - -load_nav.php -------------- + + include_php + + + + + + + + + + Attribute Name + Type + Required + Default + Description + + + + + file + string + Yes + n/a + The name of the php file to include + + + once + boolean + No + true + whether or not to include the php file more than + once if included multiple times + + + assign + string + No + n/a + The name of the variable that the output of + include_php will be assigned to + + + + + + Technical Note + + include_php is pretty much deprecated from Smarty, you can + accomplish the same functionality via a custom template function. + The only reason to use include_php is if you really have a need to + quarantine the php function away from the plugin directory or your + application code. See the componentized template + example for details. + + + + include_php tags are used to include a php script in your template. + If security is enabled, then the php script must be located in the + $trusted_dir path. The include_php tag must have the attribute + "file", which contains the path to the included php file, either + relative to $trusted_dir, or an absolute path. + + + include_php is a nice way to handle componentized templates, and + keep PHP code separate from the template files. Lets say you have a + template that shows your site navigation, which is pulled + dynamically from a database. You can keep your PHP logic that grabs + database content in a separate directory, and include it at the top + of the template. Now you can include this template anywhere without + worrying if the database information was assigned by the application + before hand. + + + By default, php files are only included once even if called + multiple times in the template. You can specify that it should be + included every time with the once attribute. + Setting once to false will include the php script each time it is + included in the template. + + + You can optionally pass the assign attribute, + which will specify a template variable name that the output of + include_php will be assigned to instead of + displayed. + + + The smarty object is available as $this within the PHP script that you + include. + + + function include_php + +query("select * from site_nav_sections order by name",SQL_ALL); - $this->assign('sections',$sql->record); + // load in variables from a mysql db and assign them to the template + require_once("MySQL.class.php"); + $sql = new MySQL; + $sql->query("select * from site_nav_sections order by name",SQL_ALL); + $this->assign('sections',$sql->record); -?> - - -index.tpl ---------- - -{* absolute path, or relative to $trusted_dir *} -{include_php file="/path/to/load_nav.php"} - -{foreach item="curr_section" from=$sections} - <a href="{$curr_section.url}">{$curr_section.name}</a><br> -{/foreach} - + ?> +]]> + + + Where index.pl is: + + +{$curr_section.name}
+ {/foreach} +]]> +
+
- \ No newline at end of file + - - section,sectionelse - - - - - - - - - - Attribute Name - Type - Required - Default - Description - - - - - name - string - Yes - n/a - The name of the section - - - loop - mixed - Yes - n/a - Value to determine the number of loop iterations - - - start - integer - No - 0 The index - position that the section will begin looping. If the - value is negative, the start position is calculated - from the end of the array. For example, if there are - seven values in the loop array and start is -2, the - start index is 5. Invalid values (values outside of the - length of the loop array) are automatically truncated - to the closest valid value. - - - step - integer - No - 1 - The step value that will be used to traverse the - loop array. For example, step=2 will loop on index - 0,2,4, etc. If step is negative, it will step through - the array backwards. - - - max - integer - No - n/a - Sets the maximum number of times the section - will loop. - - - show - boolean - No - true - determines whether or not to show this section - - - - - - Template sections are used for looping over arrays of data. All - section tags must be paired with - /section tags. Required parameters are - name and loop. The name - of the section can be anything you like, made up of letters, - numbers and underscores. Sections can be nested, and the nested - section names must be unique from each other. The loop variable - (usually an array of values) determines the number of times the - section will loop. When printing a variable within a section, the - section name must be given next to variable name within brackets - []. sectionelse is - executed when there are no values in the loop variable. - - -section - + + section,sectionelse + + + + + + + + + + Attribute Name + Type + Required + Default + Description + + + + + name + string + Yes + n/a + The name of the section + + + loop + mixed + Yes + n/a + Value to determine the number of loop iterations + + + start + integer + No + 0 The index + position that the section will begin looping. If the + value is negative, the start position is calculated + from the end of the array. For example, if there are + seven values in the loop array and start is -2, the + start index is 5. Invalid values (values outside of the + length of the loop array) are automatically truncated + to the closest valid value. + + + step + integer + No + 1 + The step value that will be used to traverse the + loop array. For example, step=2 will loop on index + 0,2,4, etc. If step is negative, it will step through + the array backwards. + + + max + integer + No + n/a + Sets the maximum number of times the section + will loop. + + + show + boolean + No + true + determines whether or not to show this section + + + + + + Template sections are used for looping over arrays of data. All + section tags must be paired with + /section tags. Required parameters are + name and loop. The name + of the section can be anything you like, made up of letters, + numbers and underscores. Sections can be nested, and the nested + section names must be unique from each other. The loop variable + (usually an array of values) determines the number of times the + section will loop. When printing a variable within a section, the + section name must be given next to variable name within brackets + []. sectionelse is + executed when there are no values in the loop variable. + + + section + + + {/section} +]]> + + + The above example will output: + + + + id: 1001
+ id: 1002
+]]> +
+
-{* this example will print out all the values of the $custid array *} -{section name=customer loop=$custid} - id: {$custid[customer]}<br> -{/section} - -OUTPUT: - -id: 1000<br> -id: 1001<br> -id: 1002<br>
-
- - -section loop variable - -{* the loop variable only determines the number of times to loop. + + section loop variable + + + name: {$name[customer]}
+ address: {$address[customer]}
+

+ {/section} +]]> + + + The above example will output: + + + + name: John Smith
+ address: 253 N 45th
+

+ id: 1001
+ name: Jack Jones
+ address: 417 Mulberry ln
+

+ id: 1002
+ name: Jane Munson
+ address: 5605 apple st
+

+]]> + + - -OUTPUT: - -id: 1000<br> -name: John Smith<br> -address: 253 N 45th<br> -<p> -id: 1001<br> -name: Jack Jones<br> -address: 417 Mulberry ln<br> -<p> -id: 1002<br> -name: Jane Munson<br> -address: 5605 apple st<br> -<p> - - - -section names - -{* the name of the section can be anything you like, + + section names + + - + {section name=mydata loop=$custid} + id: {$custid[mydata]}
+ name: {$name[mydata]}
+ address: {$address[mydata]}
+

+ {/section} +]]> + + - -nested sections - -{* sections can be nested as deep as you like. With nested sections, + + nested sections + + - - - -sections and associative arrays - -{* This is an example of printing an associative array + {section name=customer loop=$custid} + id: {$custid[customer]}
+ name: {$name[customer]}
+ address: {$address[customer]}
+ {section name=contact loop=$contact_type[customer]} + {$contact_type[customer][contact]}: {$contact_info[customer][contact]}
+ {/section} +

+ {/section} +]]> + + + The above example will output: + + + + name: John Smith
+ address: 253 N 45th
+ home phone: 555-555-5555
+ cell phone: 555-555-5555
+ e-mail: john@myexample.com
+

+ id: 1001
+ name: Jack Jones
+ address: 417 Mulberry ln
+ home phone: 555-555-5555
+ cell phone: 555-555-5555
+ e-mail: jack@myexample.com
+

+ id: 1002
+ name: Jane Munson
+ address: 5605 apple st
+ home phone: 555-555-5555
+ cell phone: 555-555-5555
+ e-mail: jane@myexample.com
+

+]]> + + + + + sections and associative arrays + + + home: {$contacts[customer].home}
+ cell: {$contacts[customer].cell}
+ e-mail: {$contacts[customer].email}

+ {/section} +]]> + + + The above example will output: + + + + home: 555-555-5555
+ cell: 555-555-5555
+ e-mail: john@myexample.com

+ name: Jack Jones
+ home phone: 555-555-5555
+ cell phone: 555-555-5555
+ e-mail: jack@myexample.com

+ name: Jane Munson
+ home phone: 555-555-5555
+ cell phone: 555-555-5555
+ e-mail: jane@myexample.com

+]]> + + + + sectionelse + + + {sectionelse} + there are no values in $custid. + {/section} +]]> + + + + Sections also have their own variables that handle section properties. + These are indicated like so: {$smarty.section.sectionname.varname} + + + + As of Smarty 1.5.0, the syntax for section property variables has + been changed from {%sectionname.varname%} to + {$smarty.section.sectionname.varname}. The old syntax is still + supported, but you will only see reference to the new syntax in the + manual examples. + + + + 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, except it starts on 0 instead of 1. + + + + section property index + + + {/section} +]]> + + + The above example will output: + + + + 1 id: 1001
+ 2 id: 1002
+]]> +
+
+
+ + 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 + + + {* FYI, $custid[customer.index] and $custid[customer] are identical in meaning *} + {if $custid[customer.index_prev] ne $custid[customer.index]} + The customer id changed
+ {/if} + {/section} +]]> +
+ + The above example will output: + + + + The customer id changed
+ 1 id: 1001
+ The customer id changed
+ 2 id: 1002
+ The customer id changed
+]]> +
+
+
+ + 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 + + + {* 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
+ {/if} + {/section} +]]> +
+ + The above example will output: + + + + The customer id will change
+ 1 id: 1001
+ The customer id will change
+ 2 id: 1002
+ The customer id will change
+]]> +
+
+
+ + iteration + + iteration is used to display the current loop iteration. + + + + This is not affected by the section properties start, step and + max, unlike the index property. Iteration also starts with 1 + instead of 0 like index. rownum is an alias to iteration, they work + identical. + + + + section property iteration + + + {$smarty.section.customer.index} id: {$custid[customer]}
+ {* 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
+ {/if} + {/section} +]]> +
+ + The above example will output: + + + + The customer id will change
+ current loop iteration: 2 + 7 id: 1001
+ The customer id will change
+ current loop iteration: 3 + 9 id: 1002
+ The customer id will change
+]]> +
+
+
+ + first + + first is set to true if the current section iteration is the first + one. + + + section property first + + + {/if} -OUTPUT: + {$smarty.section.customer.index} id: + {$custid[customer]} -name: John Smith<br> -home: 555-555-5555<br> -cell: 555-555-5555<br> -e-mail: john@myexample.com<p> -name: Jack Jones<br> -home phone: 555-555-5555<br> -cell phone: 555-555-5555<br> -e-mail: jack@myexample.com<p> -name: Jane Munson<br> -home phone: 555-555-5555<br> -cell phone: 555-555-5555<br> -e-mail: jane@myexample.com<p> - + {if $smarty.section.customer.last} + + {/if} + {/section} +]]> + + + The above example will output: + + + + 0 id: 1000 + 1 id: 1001 + 2 id: 1002 + +]]> + + + + + last + + last is set to true if the current section iteration is the last + one. + + + section property last + + + {/if} + {$smarty.section.customer.index} id: + {$custid[customer]} + {if $smarty.section.customer.last} + + {/if} + {/section} +]]> + + + The above example will output: + + + + 0 id: 1000 + 1 id: 1001 + 2 id: 1002 + +]]> + + + + + rownum + + rownum is used to display the current loop iteration, + starting with one. It is an alias to iteration, they work + identically. + + + section property rownum + + + {/section} +]]> + + + The above example will output: + + + + 2 id: 1001
+ 3 id: 1002
+]]> +
+
+
+ + 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} - -sectionelse - -{* sectionelse will execute if there are no $custid values *} -{section name=customer loop=$custid} - id: {$custid[customer]}<br> -{sectionelse} - there are no values in $custid. -{/section} - - - Sections also have their own variables that handle section properties. - These are indicated like so: {$smarty.section.sectionname.varname} - - - - As of Smarty 1.5.0, the syntax for section property variables has - been changed from {%sectionname.varname%} to - {$smarty.section.sectionname.varname}. The old syntax is still - supported, but you will only see reference to the new syntax in the - manual examples. - - - - 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, except it starts on 0 instead of 1. - - - - section property index - - {section name=customer loop=$custid} - {$smarty.section.customer.index} id: {$custid[customer]}<br> - {/section} + There were {$smarty.section.customer.loop} customers shown above. +]]> + + + The above example will output: + + + + 1 id: 1001
+ 2 id: 1002
+ 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. + + + section attribute show + + + {/section} - OUTPUT: + {if $smarty.section.customer.show} + the section was shown. + {else} + the section was not shown. + {/if} +]]> + + + The above example will output: + + + + 2 id: 1001
+ 3 id: 1002
- 0 id: 1000<br> - 1 id: 1001<br> - 2 id: 1002<br> -
-
-
- - 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} - {$smarty.section.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} + 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. + + + section property total + + + {/section} + There were {$smarty.section.customer.total} customers shown above. +]]> + + + The above example will output: + + + + 2 id: 1001
+ 4 id: 1002
- OUTPUT: - - 0 id: 1000<br> - The customer id changed<br> - 1 id: 1001<br> - The customer id changed<br> - 2 id: 1002<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.) - - - section property index_next - - {section name=customer loop=$custid} - {$smarty.section.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> - 1 id: 1001<br> - The customer id will change<br> - 2 id: 1002<br> - The customer id will change<br> - - - - - iteration - - iteration is used to display the current loop iteration. - - - - This is not affected by the section properties start, step and - max, unlike the index property. Iteration also starts with 1 - instead of 0 like index. rownum is an alias to iteration, they work - identical. - - - - section property iteration - - {section name=customer loop=$custid start=5 step=2} - current loop iteration: {$smarty.section.customer.iteration}<br> - {$smarty.section.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: - - current loop iteration: 1 - 5 id: 1000<br> - The customer id will change<br> - current loop iteration: 2 - 7 id: 1001<br> - The customer id will change<br> - current loop iteration: 3 - 9 id: 1002<br> - The customer id will change<br> - - - - - first - - first is set to true if the current section iteration is the first - one. - - - section property first - - {section name=customer loop=$custid} - {if $smarty.section.customer.first} - <table> - {/if} - - <tr><td>{$smarty.section.customer.index} id: - {$custid[customer]}</td></tr> - - {if $smarty.section.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> - </table> - - - - - last - - last is set to true if the current section iteration is the last - one. - - - section property last - - {section name=customer loop=$custid} - {if $smarty.section.customer.first} - <table> - {/if} - - <tr><td>{$smarty.section.customer.index} id: - {$custid[customer]}</td></tr> - - {if $smarty.section.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> - </table> - - - - - rownum - - rownum is used to display the current loop iteration, - starting with one. It is an alias to iteration, they work - identically. - - - section property rownum - - {section name=customer loop=$custid} - {$smarty.section.customer.rownum} id: {$custid[customer]}<br> - {/section} - - - OUTPUT: - - 1 id: 1000<br> - 2 id: 1001<br> - 3 id: 1002<br> - - - - - 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} - {$smarty.section.customer.index} id: {$custid[customer]}<br> - {/section} - - There were {$smarty.section.customer.loop} customers shown above. - - OUTPUT: - - 0 id: 1000<br> - 1 id: 1001<br> - 2 id: 1002<br> - - 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. - - - section attribute show - - {* $show_customer_info may have been passed from the PHP - application, to regulate whether or not this section shows *} - {section name=customer loop=$custid show=$show_customer_info} - {$smarty.section.customer.rownum} id: {$custid[customer]}<br> - {/section} - - {if $smarty.section.customer.show} - the section was shown. - {else} - the section was not shown. - {/if} - - - OUTPUT: - - 1 id: 1000<br> - 2 id: 1001<br> - 3 id: 1002<br> - - 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. - - - section property total - - {section name=customer loop=$custid step=2} - {$smarty.section.customer.index} id: {$custid[customer]}<br> - {/section} - - There were {$smarty.section.customer.total} customers shown above. - - OUTPUT: - - 0 id: 1000<br> - 2 id: 1001<br> - 4 id: 1002<br> - - There were 3 customers shown above. - - - + There were 3 customers shown above. +]]> + + + - - eval - - - - - - - - - - Attribute Name - Type - Required - Default - Description - - - - - var - mixed - Yes - n/a - variable (or string) to evaluate - - - assign - string - No - n/a - the template variable the output will be assigned - to - - - - - - eval is used to evaluate a variable as a template. This can be used - for things like embedding template tags/variables into variables or - tags/variables into config file variables. - - - If you supply the special "assign" attribute, the output of the - eval function will be assigned to this template variable instead of - being output to the template. - - - Technical Note - - Evaluated variables are treated the same as templates. They follow - the same escapement and security features just as if they were - templates. - - - - Technical Note - - Evaluated variables are compiled on every invocation, the compiled - versions are not saved! However if you have caching enabled, the - output will be cached with the rest of the template. - - - -eval - -setup.conf ----------- + + eval + + + + + + + + + + Attribute Name + Type + Required + Default + Description + + + + + var + mixed + Yes + n/a + variable (or string) to evaluate + + + assign + string + No + n/a + the template variable the output will be assigned + to + + + + + + eval is used to evaluate a variable as a template. This can be used + for things like embedding template tags/variables into variables or + tags/variables into config file variables. + + + If you supply the special "assign" attribute, the output of the + eval function will be assigned to this template variable instead of + being output to the template. + + + Technical Note + + Evaluated variables are treated the same as templates. They follow + the same escapement and security features just as if they were + templates. + + + + Technical Note + + Evaluated variables are compiled on every invocation, the compiled + versions are not saved! However if you have caching enabled, the + output will be cached with the rest of the template. + + + + eval + + + emphend = + title = Welcome to {$company}'s home page! + ErrorCity = You must supply a {#emphstart#}city{#emphend#}. + ErrorState = You must supply a {#emphstart#}state{#emphend#}. +]]> + + + Where index.tpl is: + + + + + + The above example will output: + + +city. + You must supply a state. -{config_load file="setup.conf"} - -{eval var=$foo} -{eval var=#title#} -{eval var=#ErrorCity#} -{eval var=#ErrorState# assign="state_error"} -{$state_error} - -OUTPUT: - -This is the contents of foo. -Welcome to Foobar Pub & Grill's home page! -You must supply a <b>city</b>. -You must supply a <b>state</b>. - - - +]]> + + - - html_image - - - - - - - - - - Attribute Name - Type - Required - Default - Description - - - - - file - string - Yes - n/a - name/path to image - - - height - string - No - actual image height - height to display image - - - width - string - No - actual image width - width to display image - - - basedir - string - no - web server doc root - directory to base relative paths from - - - alt - string - no - "" - alternative description of the image - - - href - string - no - n/a - href value to link the image to - - - - - - html_image is a custom function that generates an HTML tag for an - image. The height and width are automatically calculated from the - image file if none are supplied. - - - basedir is the base directory that relative image paths are based - from. If not given, the web server document root (env variable - DOCUMENT_ROOT) is used as the base. If security is enabled, the - path to the image must be within a secure directory. - - - href is the href value to link the image to. If link is supplied, an - <a href="LINKVALUE"><a> tag is put around the image tag. - - - All parameters that are not in the list above are printed as - name/value-pairs inside the created <img>-tag. - - - Technical Note - - html_image requires a hit to the disk to read the image and - calculate the height and width. If you don't use template - caching, it is generally better to avoid html_image and leave - image tags static for optimal performance. - - - - html_image example - + + html_image + + + + + + + + + + Attribute Name + Type + Required + Default + Description + + + + + file + string + Yes + n/a + name/path to image + + + height + string + No + actual image height + height to display image + + + width + string + No + actual image width + width to display image + + + basedir + string + no + web server doc root + directory to base relative paths from + + + alt + string + no + "" + alternative description of the image + + + href + string + no + n/a + href value to link the image to + + + + + + html_image is a custom function that generates an HTML tag for an + image. The height and width are automatically calculated from the + image file if none are supplied. + + + basedir is the base directory that relative image paths are based + from. If not given, the web server document root (env variable + DOCUMENT_ROOT) is used as the base. If security is enabled, the + path to the image must be within a secure directory. + + + href is the href value to link the image to. If link is supplied, an + <a href="LINKVALUE"><a> tag is put around the image tag. + + + All parameters that are not in the list above are printed as + name/value-pairs inside the created <img>-tag. + + + Technical Note + + html_image requires a hit to the disk to read the image and + calculate the height and width. If you don't use template + caching, it is generally better to avoid html_image and leave + image tags static for optimal performance. + + + + html_image example + display('index.tpl'); + require('Smarty.class.php'); + $smarty = new Smarty; + $smarty->display('index.tpl'); ?> -]]> - - - where index.tpl is: - - + ]]> + + + where index.tpl is: + + - - - a possible output would be: - - + + + a possible output would be: + + ]]> - - + + - html_options + html_options - - - - - - + + + + + + Attribute Name Type @@ -57,99 +57,119 @@ - - html_options is a custom function that creates html option group - with provided data. It takes care of which item(s) are selected by - default as well. Required attributes are values and output, unless - you use options instead. - - - If a given value is an array, it will treat it as an html OPTGROUP, - and display the groups. Recursion is supported with OPTGROUP. All - output is XHTML compatible. - - - If the optional name attribute is given, the - <select name="groupname"></select> tags will enclose - the option list. Otherwise only the option list is generated. - - - All parameters that are not in the list above are printed as - name/value-pairs inside the <select>-tag. They are ignored if - the optional name is not given. - - -html_options - -EXAMPLE 1 ---------- + + html_options is a custom function that creates html option group + with provided data. It takes care of which item(s) are selected by + default as well. Required attributes are values and output, unless + you use options instead. + + + If a given value is an array, it will treat it as an html OPTGROUP, + and display the groups. Recursion is supported with OPTGROUP. All + output is XHTML compatible. + + + If the optional name attribute is given, the + tags will enclose + the option list. Otherwise only the option list is generated. + + + All parameters that are not in the list above are printed as + name/value-pairs inside the +]]> + + + Example 2 + + +assign('cust_options', array( + 1001 => 'Joe Schmoe', + 1002 => 'Jack Smith', + 1003 => 'Jane Johnson', + 1004 => 'Charlie Brown')); + $smarty->assign('customer_id', 1001); + $smarty->display('index.tpl'); +]]> + + + Where index.tpl is: + + + + {html_options options=$cust_options selected=$customer_id} + -EXAMPLE 2 ---------- +]]> + + + Both examples will output: + + + + + + + + -require('Smarty.class.php'); -$smarty = new Smarty; -$smarty->assign('cust_options', array( - 1001 => 'Joe Schmoe', - 1002 => 'Jack Smith', - 1003 => 'Jane Johnson', - 1004 => 'Charlie Brown')); -$smarty->assign('customer_id', 1001); -$smarty->display('index.tpl'); - -index.tpl: - -<select name=customer_id> - {html_options options=$cust_options selected=$customer_id} -</select> - - -OUTPUT: (both examples) ------------------------ - -<select name=customer_id> - <option label="Joe Schmoe" value="1000">Joe Schmoe</option> - <option label="Jack Smith" value="1001" selected="selected">Jack Smith</option> - <option label="Jane Johnson" value="1002">Jane Johnson</option> - <option label="Charlie Brown" value="1003">Charlie Brown</option> -</select> - +]]> + + + Local variables: + mode: sgml + sgml-omittag:t + sgml-shorttag:t + sgml-minimize-attributes:nil + sgml-always-quote-attributes:t + sgml-indent-step:1 + sgml-indent-data:t + indent-tabs-mode:nil + sgml-parent-document:nil + sgml-default-dtd-file:"../../../../manual.ced" + sgml-exposed-tags:nil + sgml-local-catalogs:nil + sgml-local-ecat-files:nil + End: + vim600: syn=xml fen fdm=syntax fdl=2 si + vim: et tw=78 syn=sgml + vi: ts=1 sw=1 + --> diff --git a/docs/en/designers/language-custom-functions/language-function-html-radios.xml b/docs/en/designers/language-custom-functions/language-function-html-radios.xml index bba0bfd1..f3348fa8 100644 --- a/docs/en/designers/language-custom-functions/language-function-html-radios.xml +++ b/docs/en/designers/language-custom-functions/language-function-html-radios.xml @@ -1,125 +1,145 @@ - - html_radios - - - - - - - - - - Attribute Name - Type - Required - Default - Description - - - - - name - string - No - radio - name of radio list - - - values - array - Yes, unless using options attribute - n/a - an array of values for radio buttons - - - output - array - Yes, unless using options attribute - n/a - an array of output for radio buttons - - - selected - string - No - empty - the selected radio element - - - options - associative array - Yes, unless using values and output - n/a - an associative array of values and output - - - separator - string - No - empty - string of text to separate each radio item - - - - - - html_radios is a custom function that creates html radio button - group with provided data. It takes care of which item is selected - by default as well. Required attributes are values and output, - unless you use options instead. All output is XHTML compatible. - - - All parameters that are not in the list above are printed as - name/value-pairs inside each of the created <input>-tags. - + + html_radios + + + + + + + + + + Attribute Name + Type + Required + Default + Description + + + + + name + string + No + radio + name of radio list + + + values + array + Yes, unless using options attribute + n/a + an array of values for radio buttons + + + output + array + Yes, unless using options attribute + n/a + an array of output for radio buttons + + + selected + string + No + empty + the selected radio element + + + options + associative array + Yes, unless using values and output + n/a + an associative array of values and output + + + separator + string + No + empty + string of text to separate each radio item + + + + + + html_radios is a custom function that creates html radio button + group with provided data. It takes care of which item is selected + by default as well. Required attributes are values and output, + unless you use options instead. All output is XHTML compatible. + + + All parameters that are not in the list above are printed as + name/value-pairs inside each of the created -tags. + - -html_radios - -index.php: + + html_radios : Example 1 + + - + require('Smarty.class.php'); + $smarty = new Smarty; + $smarty->assign('cust_ids', array(1000,1001,1002,1003)); + $smarty->assign('cust_names', array('Joe Schmoe','Jack Smith','Jane + Johnson','Charlie Brown')); + $smarty->assign('customer_id', 1001); + $smarty->display('index.tpl'); +]]> + + + Where index.tpl is: + + +"} + ]]> + + + Example 2 : + + +assign('cust_radios', array( + 1000 => 'Joe Schmoe', + 1001 => 'Jack Smith', + 1002 => 'Jane Johnson', + 1003 => 'Charlie Brown')); + $smarty->assign('customer_id', 1001); + $smarty->display('index.tpl'); +]]> + + + Where index.tpl is: + + +"} +]]> + + + Both examples will output: + + +Joe Schmoe
+
+
+
+]]> +
+
+ + +]]> + +
+ Local variables: + mode: sgml + sgml-omittag:t + sgml-shorttag:t + sgml-minimize-attributes:nil + sgml-always-quote-attributes:t + sgml-indent-step:1 + sgml-indent-data:t + indent-tabs-mode:nil + sgml-parent-document:nil + sgml-default-dtd-file:"../../../../manual.ced" + sgml-exposed-tags:nil + sgml-local-catalogs:nil + sgml-local-ecat-files:nil + End: + vim600: syn=xml fen fdm=syntax fdl=2 si + vim: et tw=78 syn=sgml + vi: ts=1 sw=1 + -->