mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 10:24:26 +02:00
allow $foo->bar[$j].blah type of syntax
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
title = Welcome to Smarty!
|
||||
cutoff_size = 40
|
||||
foo = foo_var
|
||||
|
||||
[setup]
|
||||
bold = true
|
||||
[foo]
|
||||
|
||||
foo = section_foo_var
|
||||
|
@@ -1,5 +1,5 @@
|
||||
title = Welcome to Smarty!
|
||||
cutoff_size = 40
|
||||
foo = foo_var
|
||||
|
||||
[setup]
|
||||
bold = true
|
||||
[foo]
|
||||
|
||||
foo = section_foo_var
|
||||
|
@@ -1,24 +1,76 @@
|
||||
<?php
|
||||
|
||||
require 'Smarty.class.php';
|
||||
require("Smarty.class.php");
|
||||
|
||||
error_reporting(E_ALL);
|
||||
|
||||
$smarty = new Smarty;
|
||||
$smarty->force_compile = true;
|
||||
//$smarty->left_delimiter = '<!---';
|
||||
//$smarty->right_delimiter = '--->';
|
||||
//$smarty->plugins_dir = array('plugins','./my_plugins');
|
||||
$smarty->plugins_dir = './plugins';
|
||||
//$smarty->use_sub_dirs = false;
|
||||
//$smarty->caching = true;
|
||||
//$smarty->cache_modified_check = true;
|
||||
//$smarty->compile_check = false;
|
||||
//$smarty->security = true;
|
||||
//$smarty->security_settings['ALLOW_CONSTANTS'] = true;
|
||||
//$smarty->trusted_dir=array("./trusted");
|
||||
//$smarty->secure_dir=array("./templates");
|
||||
//$smarty->default_template_handler_func = "make_tpl";
|
||||
|
||||
$smarty->compile_check = true;
|
||||
$smarty->debugging = true;
|
||||
//$smarty->debugging=true;
|
||||
|
||||
$smarty->assign("Name","Fred Irving Johnathan Bradley Peppergill");
|
||||
$smarty->assign("FirstName",array("John","Mary","James","Henry"));
|
||||
$smarty->assign("LastName",array("Doe","Smith","Johnson","Case"));
|
||||
$smarty->assign("Class",array(array("A","B","C","D"), array("E", "F", "G", "H"),
|
||||
array("I", "J", "K", "L"), array("M", "N", "O", "P")));
|
||||
define('_MY_CONST','myconst');
|
||||
|
||||
$smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"),
|
||||
array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234")));
|
||||
$smarty->assign('foo','bar');
|
||||
$smarty->assign('bfoo',true);
|
||||
$smarty->assign('bar','one');
|
||||
$smarty->assign('afoo',array('one' => 'foo', 'two' => 'bar'));
|
||||
|
||||
$smarty->assign("option_values", array("NY","NE","KS","IA","OK","TX"));
|
||||
$smarty->assign("option_output", array("New York","Nebraska","Kansas","Iowa","Oklahoma","Texas"));
|
||||
$smarty->assign("option_selected", "NE");
|
||||
class ofoo {
|
||||
var $blah = 'myblah';
|
||||
function foo($var=null,$var2=null,$var3=null) {
|
||||
return '[' . $var . '][' . $var2 . '][' . $var3 . ']';
|
||||
}
|
||||
}
|
||||
|
||||
$ofoo = new ofoo;
|
||||
|
||||
$smarty->assign('ofoo',$ofoo);
|
||||
|
||||
class nfoo {
|
||||
var $ofoo = null;
|
||||
function nfoo() {
|
||||
$this->ofoo = new ofoo;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$nfoo = new nfoo;
|
||||
|
||||
$smarty->assign('nfoo',$nfoo);
|
||||
|
||||
|
||||
function _smarty_ffoo($params, &$smarty) {
|
||||
foreach($params as $var) {
|
||||
$return .= '[' . $var . ']';
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
$smarty->register_function('ffoo','_smarty_ffoo');
|
||||
|
||||
$smarty->assign('sfoo',array('one','two','three'));
|
||||
|
||||
function smarty_block_reverse($params, $content, &$smarty) {
|
||||
if($content) {
|
||||
return strrev($content);
|
||||
}
|
||||
}
|
||||
|
||||
$smarty->register_block('reverse', 'smarty_block_reverse');
|
||||
|
||||
$smarty->display('index.tpl');
|
||||
|
||||
|
@@ -1,83 +1,189 @@
|
||||
{config_load file=test.conf section="setup"}
|
||||
{include file="header.tpl" title=foo}
|
||||
|
||||
<PRE>
|
||||
|
||||
{* bold and title are read from the config file *}
|
||||
{if #bold#}<b>{/if}
|
||||
{* capitalize the first letters of each word of the title *}
|
||||
Title: {#title#|capitalize}
|
||||
{if #bold#}</b>{/if}
|
||||
|
||||
The current date and time is {$smarty.now|date_format:"%Y-%m-%d %H:%M:%S"}
|
||||
|
||||
Tooltip example: Move your mouse over the <A HREF="" {popup sticky=true caption="Smarty pop-up text" delay=400 text="This is an example of a tooltip. Tooltips are handy for context sensitive information, and extremely easy to add to your templates with Smarty and the integration of <a href='http://www.bosrup.com/web/overlib/'>overLIB</a> by Erik Bosrup"} onclick="return false;">Help</A> link to see an example of a tooltip using Smarty's popup function.
|
||||
|
||||
The value of global assigned variable $SCRIPT_NAME is {$SCRIPT_NAME}
|
||||
|
||||
Example of accessing server environment variable SERVER_NAME: {$smarty.server.SERVER_NAME}
|
||||
|
||||
The value of {ldelim}$Name{rdelim} is <b>{$Name}</b>
|
||||
|
||||
variable modifier example of {ldelim}$Name|upper{rdelim}
|
||||
|
||||
<b>{$Name|upper}</b>
|
||||
{* Smarty *}
|
||||
BEGIN SMARTY SMOKE TEST
|
||||
|
||||
|
||||
An example of a section loop:
|
||||
plain variable $foo
|
||||
-------------------
|
||||
|
||||
$foo {$foo}
|
||||
$foo|upper {$foo|upper}
|
||||
$foo|upper|spacify {$foo|upper|spacify}
|
||||
$foo|spacify:"^^" {$foo|spacify:"^^"}
|
||||
$foo|@count {$foo|@count}
|
||||
$foo|default:"no" {$foo|default:"no"}
|
||||
$foo|truncate:6:"...":true {$foo|truncate:6:"...":true}
|
||||
|
||||
associative variable $afoo
|
||||
--------------------------
|
||||
|
||||
$afoo.one {$afoo.one}
|
||||
$afoo.two {$afoo.two}
|
||||
$afoo.one|upper {$afoo.one|upper}
|
||||
$afoo.one|upper|spacify {$afoo.one|upper|spacify}
|
||||
$afoo.one|spacify:"^^" {$afoo.one|spacify:"^^"}
|
||||
$afoo.one|@count {$afoo.one|@count}
|
||||
$afoo.one|default:"no" {$afoo.one|default:"no"}
|
||||
$afoo.one|truncate:6:"...":true {$afoo.one|truncate:6:"...":true}
|
||||
$afoo.$bar {$afoo.$bar}
|
||||
|
||||
{config_load file="test.conf"}
|
||||
|
||||
config variable #foo#
|
||||
---------------------
|
||||
|
||||
#foo# {#foo#}
|
||||
#foo#|upper {#foo#|upper}
|
||||
#foo#|upper|spacify {#foo#|upper|spacify}
|
||||
#foo#|spacify:"^^" {#foo#|spacify:"^^"}
|
||||
#foo#|@count {#foo#|@count}
|
||||
#foo#|default:"no" {#foo#|default:"no"}
|
||||
#foo#|truncate:6:"...":true {#foo#|truncate:6:"...":true}
|
||||
|
||||
{config_load file="test.conf" section="foo"}
|
||||
|
||||
config variable #foo# from section foo
|
||||
--------------------------------------
|
||||
|
||||
#foo# {#foo#}
|
||||
#foo#|upper {#foo#|upper}
|
||||
#foo#|upper|spacify {#foo#|upper|spacify}
|
||||
#foo#|spacify:"^^" {#foo#|spacify:"^^"}
|
||||
#foo#|@count {#foo#|@count}
|
||||
#foo#|default:"no" {#foo#|default:"no"}
|
||||
#foo#|truncate:6:"...":true {#foo#|truncate:6:"...":true}
|
||||
|
||||
object $ofoo
|
||||
------------
|
||||
|
||||
$ofoo->blah {$ofoo->blah}
|
||||
$ofoo->foo('bar') {$ofoo->foo('bar')}
|
||||
$ofoo->foo("bar") {$ofoo->foo("bar")}
|
||||
$ofoo->foo("$foo bar") {$ofoo->foo("$foo bar")}
|
||||
$ofoo->foo("one","two") {$ofoo->foo("one","two")}
|
||||
$ofoo->foo("one","two","three") {$ofoo->foo("one","two","three")}
|
||||
$ofoo->foo("one $foo","two","three") {$ofoo->foo("one $foo","two","three")}
|
||||
$ofoo->foo("one $foo","two $foo","three") {$ofoo->foo("one $foo","two $foo","three")}
|
||||
$ofoo->foo("one","two","three") {$ofoo->foo("one","two","three","four")}
|
||||
$ofoo->foo('one $foo','two $foo','three') {$ofoo->foo('one $foo','two $foo','three')}
|
||||
$ofoo->foo('one')|upper {$ofoo->foo('one')|upper}
|
||||
|
||||
|
||||
nested object nfoo
|
||||
------------------
|
||||
|
||||
|
||||
$nfoo->ofoo->blah {$nfoo->ofoo->blah}
|
||||
$nfoo->ofoo->foo('bar') {$nfoo->ofoo->foo('bar')}
|
||||
$nfoo->ofoo->foo("bar") {$nfoo->ofoo->foo("bar")}
|
||||
$nfoo->ofoo->foo("$foo bar") {$nfoo->ofoo->foo("$foo bar")}
|
||||
$nfoo->ofoo->foo("one","two") {$nfoo->ofoo->foo("one","two")}
|
||||
$nfoo->ofoo->foo("one","two","three") {$nfoo->ofoo->foo("one","two","three")}
|
||||
$nfoo->ofoo->foo("one $foo","two","three") {$nfoo->ofoo->foo("one $foo","two","three")}
|
||||
$nfoo->ofoo->foo("one $foo","two $foo","three") {$nfoo->ofoo->foo("one $foo","two $foo","three")}
|
||||
$nfoo->ofoo->foo("one","two","three") {$nfoo->ofoo->foo("one","two","three","four")}
|
||||
$nfoo->ofoo->foo('one $foo','two $foo','three') {$nfoo->ofoo->foo('one $foo','two $foo','three')}
|
||||
$nfoo->ofoo->foo('one')|upper {$nfoo->ofoo->foo('one')|upper}
|
||||
|
||||
|
||||
function ffoo
|
||||
-------------
|
||||
|
||||
ffoo var="foo" {ffoo var="foo"}
|
||||
ffoo var="foo" var2="blah" {ffoo var="foo" var2="blah"}
|
||||
ffoo var=$foo {ffoo var=$foo}
|
||||
ffoo var=truey {ffoo var=truey}
|
||||
ffoo var=$foo|upper {ffoo var=$foo|upper}
|
||||
ffoo var="foo"|upper {ffoo var="foo"|upper}
|
||||
ffoo var=$ofoo->foo("$foo bar") {ffoo var=$ofoo->foo("$foo bar")}
|
||||
ffoo|upper var=$foo {ffoo|upper var=$foo}
|
||||
|
||||
|
||||
|
||||
section loop over sfoo
|
||||
----------------------
|
||||
|
||||
{section name=sec loop=$sfoo}
|
||||
$sfoo[sec] {$sfoo[sec]}
|
||||
$sfoo[sec.index] {$sfoo[sec.index]}
|
||||
$sfoo[sec.index_next] {$sfoo[sec.index_next]}
|
||||
$sfoo[sec.index_prev] {$sfoo[sec.index_prev]}
|
||||
$sfoo[sec.iteration] {$sfoo[sec.iteration]}
|
||||
$sfoo[sec.first] {$sfoo[sec.first]}
|
||||
$sfoo[sec.last] {$sfoo[sec.last]}
|
||||
$sfoo[sec.rownum] {$sfoo[sec.rownum]}
|
||||
$sfoo[sec.loop] {$sfoo[sec.loop]}
|
||||
$sfoo[sec.total] {$sfoo[sec.total]}
|
||||
$sfoo[sec.show] {$sfoo[sec.show]}
|
||||
$sfoo[sec]|upper {$sfoo[sec]|upper}
|
||||
$sfoo[sec]|upper|spacify {$sfoo[sec]|upper|spacify}
|
||||
$sfoo[sec]|spacify:"^^" {$sfoo[sec]|spacify:"^^"}
|
||||
$sfoo[sec]|@count {$sfoo[sec]|@count}
|
||||
$sfoo[sec]|default:"no" {$sfoo[sec]|default:"no"}
|
||||
$sfoo[sec]|truncate:6:"...":true {$sfoo[sec]|truncate:6:"...":true}
|
||||
|
||||
$smarty.section.sec.index {$smarty.section.sec.index}
|
||||
|
||||
{section name=outer loop=$FirstName}
|
||||
{if %outer.index% is odd by 2}
|
||||
{%outer.rownum%} . {$FirstName[outer]} {$LastName[outer]}
|
||||
{else}
|
||||
{%outer.rownum%} * {$FirstName[outer]} {$LastName[outer]}
|
||||
{/if}
|
||||
{sectionelse}
|
||||
none
|
||||
{/section}
|
||||
|
||||
An example of section looped key values:
|
||||
if statement parse test
|
||||
-----------------------
|
||||
|
||||
{section name=sec1 loop=$contacts}
|
||||
phone: {$contacts[sec1].phone}<br>
|
||||
fax: {$contacts[sec1].fax}<br>
|
||||
cell: {$contacts[sec1].cell}<br>
|
||||
if $foo {if $foo}{/if}(end)
|
||||
if $foo eq "bar" {if $foo eq "bar"}foo is bar{/if}(end)
|
||||
if is_array($foo) {if is_array($foo)}foo is array{else}foo is not array{/if}(end)
|
||||
if $foo gt 4 {if $foo gt 4}$foo is gt 4{/if}(end)
|
||||
if ($foo gt 4) {if ($foo gt 4)}$foo is gt 4{/if}(end)
|
||||
if ( $foo gt 4 ) {if ( $foo gt 4 )}$foo is gt 4{/if}(end)
|
||||
if $foo and not $bar {if $foo and not $bar}foo and not bar{/if}(end)
|
||||
if !$bfoo {if !$bfoo}not bfoo{else}bfoo{/if}(end)
|
||||
if 4 is div by 4 {if 4 is div by 4}div by 4{else}not div by 4{/if}(end)
|
||||
if 3 is div by 4 {if 3 is div by 4}div by 4{else}not div by 4{/if}(end)
|
||||
if 3 is div by 4 or ( 3 eq 3 ) {if 3 is div by 4 or ( 3 eq 3 )}blah{/if}(end)
|
||||
if (3 is div by 4) or ( 3<="bah"|upper ) {if (3 is div by 4) or ( 3<="bah"|upper )}woohoo{/if}(end)
|
||||
if in_array("my $bar", $afoo) {if in_array("my $bar", $afoo)}is in{else}is not in{/if}(end)
|
||||
if $ofoo->foo() {if $ofoo->foo()}is in{else}is not in{/if}(end)
|
||||
if in_array($ofoo->foo("two"), $afoo) {if in_array($ofoo->foo("two"), $afoo)}is in{else}is not in{/if}(end)
|
||||
|
||||
$smarty variable access
|
||||
-----------------------
|
||||
|
||||
$smarty.now {$smarty.now}
|
||||
$smarty.const._MY_CONST {$smarty.const._MY_CONST}
|
||||
|
||||
block function
|
||||
--------------
|
||||
|
||||
{reverse}
|
||||
This is my block of text.
|
||||
{/reverse|upper}
|
||||
|
||||
misc syntax, try to break
|
||||
-------------------------
|
||||
|
||||
$foo|spacify:"|" {$foo|spacify:"|"}
|
||||
$foo|spacify:"|"|upper {$foo|spacify:"|"|upper}
|
||||
$foo|spacify:"$foo"|upper|default:"|" {$foo|spacify:"$foo"|upper|default:"|"}
|
||||
|
||||
{section name=sec loop=$sfoo}
|
||||
$ofoo->foo($sfoo[sec],$sfoo[sec]|spacify:"^^",$sfoo[sec]|truncate:6:"...":true) {$ofoo->foo($sfoo[sec],$sfoo[sec]|spacify:"^^",$sfoo[sec]|truncate:6:"...":true)}
|
||||
$nfoo->ofoo->foo($sfoo[sec],$sfoo[sec]|spacify:"^^",$sfoo[sec]|truncate:6:"...":true) {$nfoo->ofoo->foo($sfoo[sec],$sfoo[sec]|spacify:"^^",$sfoo[sec]|truncate:6:"...":true)}
|
||||
{/section}
|
||||
<p>
|
||||
|
||||
testing strip tags
|
||||
{strip}
|
||||
<table border=0>
|
||||
<tr>
|
||||
<td>
|
||||
<A HREF="{$SCRIPT_NAME}">
|
||||
<font color="red">This is a test </font>
|
||||
</A>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
{/strip}
|
||||
ffoo|spacify:"|"|upper var="lalala" {ffoo|spacify:"|"|upper var="lalala"}
|
||||
ffoo|spacify:" my spaces "|upper var="lalala" {ffoo|spacify:" my spaces "|upper var="lalala"}
|
||||
ffoo|spacify:"!@#$%^&*()_+=-\|]["|upper var="lalala" {ffoo|spacify:"!@#$%^&*()_+=-\|]["|upper var="lalala"}
|
||||
|
||||
</PRE>
|
||||
{config_load file=test.conf section=foo}
|
||||
|
||||
This is an example of the html_select_date function:
|
||||
if !$nfoo->ofoo->foo("blah blah") {if !$nfoo->ofoo->foo("blah blah")}not blah{else}blah{/if}(end)
|
||||
|
||||
<form>
|
||||
{html_select_date start_year=1998 end_year=2010}
|
||||
</form>
|
||||
"static"|upper {"static"|upper}
|
||||
|
||||
This is an example of the html_select_time function:
|
||||
{foreach item="fofoo" from=$afoo}
|
||||
|
||||
<form>
|
||||
{html_select_time use_24_hours=false}
|
||||
</form>
|
||||
DEBUG FOREACH: {$fofoo}
|
||||
|
||||
This is an example of the html_options function:
|
||||
{/foreach}
|
||||
|
||||
<form>
|
||||
<select name=states>
|
||||
{html_options values=$option_values selected=$option_selected output=$option_output}
|
||||
</select>
|
||||
</form>
|
||||
END SMARTY SMOKE TEST
|
||||
|
||||
{include file="footer.tpl"}
|
||||
|
78
index.php
78
index.php
@@ -1,24 +1,76 @@
|
||||
<?php
|
||||
|
||||
require 'Smarty.class.php';
|
||||
require("Smarty.class.php");
|
||||
|
||||
error_reporting(E_ALL);
|
||||
|
||||
$smarty = new Smarty;
|
||||
$smarty->force_compile = true;
|
||||
//$smarty->left_delimiter = '<!---';
|
||||
//$smarty->right_delimiter = '--->';
|
||||
//$smarty->plugins_dir = array('plugins','./my_plugins');
|
||||
$smarty->plugins_dir = './plugins';
|
||||
//$smarty->use_sub_dirs = false;
|
||||
//$smarty->caching = true;
|
||||
//$smarty->cache_modified_check = true;
|
||||
//$smarty->compile_check = false;
|
||||
//$smarty->security = true;
|
||||
//$smarty->security_settings['ALLOW_CONSTANTS'] = true;
|
||||
//$smarty->trusted_dir=array("./trusted");
|
||||
//$smarty->secure_dir=array("./templates");
|
||||
//$smarty->default_template_handler_func = "make_tpl";
|
||||
|
||||
$smarty->compile_check = true;
|
||||
$smarty->debugging = true;
|
||||
//$smarty->debugging=true;
|
||||
|
||||
$smarty->assign("Name","Fred Irving Johnathan Bradley Peppergill");
|
||||
$smarty->assign("FirstName",array("John","Mary","James","Henry"));
|
||||
$smarty->assign("LastName",array("Doe","Smith","Johnson","Case"));
|
||||
$smarty->assign("Class",array(array("A","B","C","D"), array("E", "F", "G", "H"),
|
||||
array("I", "J", "K", "L"), array("M", "N", "O", "P")));
|
||||
define('_MY_CONST','myconst');
|
||||
|
||||
$smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"),
|
||||
array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234")));
|
||||
$smarty->assign('foo','bar');
|
||||
$smarty->assign('bfoo',true);
|
||||
$smarty->assign('bar','one');
|
||||
$smarty->assign('afoo',array('one' => 'foo', 'two' => 'bar'));
|
||||
|
||||
$smarty->assign("option_values", array("NY","NE","KS","IA","OK","TX"));
|
||||
$smarty->assign("option_output", array("New York","Nebraska","Kansas","Iowa","Oklahoma","Texas"));
|
||||
$smarty->assign("option_selected", "NE");
|
||||
class ofoo {
|
||||
var $blah = 'myblah';
|
||||
function foo($var=null,$var2=null,$var3=null) {
|
||||
return '[' . $var . '][' . $var2 . '][' . $var3 . ']';
|
||||
}
|
||||
}
|
||||
|
||||
$ofoo = new ofoo;
|
||||
|
||||
$smarty->assign('ofoo',$ofoo);
|
||||
|
||||
class nfoo {
|
||||
var $ofoo = null;
|
||||
function nfoo() {
|
||||
$this->ofoo = new ofoo;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$nfoo = new nfoo;
|
||||
|
||||
$smarty->assign('nfoo',$nfoo);
|
||||
|
||||
|
||||
function _smarty_ffoo($params, &$smarty) {
|
||||
foreach($params as $var) {
|
||||
$return .= '[' . $var . ']';
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
$smarty->register_function('ffoo','_smarty_ffoo');
|
||||
|
||||
$smarty->assign('sfoo',array('one','two','three'));
|
||||
|
||||
function smarty_block_reverse($params, $content, &$smarty) {
|
||||
if($content) {
|
||||
return strrev($content);
|
||||
}
|
||||
}
|
||||
|
||||
$smarty->register_block('reverse', 'smarty_block_reverse');
|
||||
|
||||
$smarty->display('index.tpl');
|
||||
|
||||
|
@@ -1,83 +1,189 @@
|
||||
{config_load file=test.conf section="setup"}
|
||||
{include file="header.tpl" title=foo}
|
||||
|
||||
<PRE>
|
||||
|
||||
{* bold and title are read from the config file *}
|
||||
{if #bold#}<b>{/if}
|
||||
{* capitalize the first letters of each word of the title *}
|
||||
Title: {#title#|capitalize}
|
||||
{if #bold#}</b>{/if}
|
||||
|
||||
The current date and time is {$smarty.now|date_format:"%Y-%m-%d %H:%M:%S"}
|
||||
|
||||
Tooltip example: Move your mouse over the <A HREF="" {popup sticky=true caption="Smarty pop-up text" delay=400 text="This is an example of a tooltip. Tooltips are handy for context sensitive information, and extremely easy to add to your templates with Smarty and the integration of <a href='http://www.bosrup.com/web/overlib/'>overLIB</a> by Erik Bosrup"} onclick="return false;">Help</A> link to see an example of a tooltip using Smarty's popup function.
|
||||
|
||||
The value of global assigned variable $SCRIPT_NAME is {$SCRIPT_NAME}
|
||||
|
||||
Example of accessing server environment variable SERVER_NAME: {$smarty.server.SERVER_NAME}
|
||||
|
||||
The value of {ldelim}$Name{rdelim} is <b>{$Name}</b>
|
||||
|
||||
variable modifier example of {ldelim}$Name|upper{rdelim}
|
||||
|
||||
<b>{$Name|upper}</b>
|
||||
{* Smarty *}
|
||||
BEGIN SMARTY SMOKE TEST
|
||||
|
||||
|
||||
An example of a section loop:
|
||||
plain variable $foo
|
||||
-------------------
|
||||
|
||||
$foo {$foo}
|
||||
$foo|upper {$foo|upper}
|
||||
$foo|upper|spacify {$foo|upper|spacify}
|
||||
$foo|spacify:"^^" {$foo|spacify:"^^"}
|
||||
$foo|@count {$foo|@count}
|
||||
$foo|default:"no" {$foo|default:"no"}
|
||||
$foo|truncate:6:"...":true {$foo|truncate:6:"...":true}
|
||||
|
||||
associative variable $afoo
|
||||
--------------------------
|
||||
|
||||
$afoo.one {$afoo.one}
|
||||
$afoo.two {$afoo.two}
|
||||
$afoo.one|upper {$afoo.one|upper}
|
||||
$afoo.one|upper|spacify {$afoo.one|upper|spacify}
|
||||
$afoo.one|spacify:"^^" {$afoo.one|spacify:"^^"}
|
||||
$afoo.one|@count {$afoo.one|@count}
|
||||
$afoo.one|default:"no" {$afoo.one|default:"no"}
|
||||
$afoo.one|truncate:6:"...":true {$afoo.one|truncate:6:"...":true}
|
||||
$afoo.$bar {$afoo.$bar}
|
||||
|
||||
{config_load file="test.conf"}
|
||||
|
||||
config variable #foo#
|
||||
---------------------
|
||||
|
||||
#foo# {#foo#}
|
||||
#foo#|upper {#foo#|upper}
|
||||
#foo#|upper|spacify {#foo#|upper|spacify}
|
||||
#foo#|spacify:"^^" {#foo#|spacify:"^^"}
|
||||
#foo#|@count {#foo#|@count}
|
||||
#foo#|default:"no" {#foo#|default:"no"}
|
||||
#foo#|truncate:6:"...":true {#foo#|truncate:6:"...":true}
|
||||
|
||||
{config_load file="test.conf" section="foo"}
|
||||
|
||||
config variable #foo# from section foo
|
||||
--------------------------------------
|
||||
|
||||
#foo# {#foo#}
|
||||
#foo#|upper {#foo#|upper}
|
||||
#foo#|upper|spacify {#foo#|upper|spacify}
|
||||
#foo#|spacify:"^^" {#foo#|spacify:"^^"}
|
||||
#foo#|@count {#foo#|@count}
|
||||
#foo#|default:"no" {#foo#|default:"no"}
|
||||
#foo#|truncate:6:"...":true {#foo#|truncate:6:"...":true}
|
||||
|
||||
object $ofoo
|
||||
------------
|
||||
|
||||
$ofoo->blah {$ofoo->blah}
|
||||
$ofoo->foo('bar') {$ofoo->foo('bar')}
|
||||
$ofoo->foo("bar") {$ofoo->foo("bar")}
|
||||
$ofoo->foo("$foo bar") {$ofoo->foo("$foo bar")}
|
||||
$ofoo->foo("one","two") {$ofoo->foo("one","two")}
|
||||
$ofoo->foo("one","two","three") {$ofoo->foo("one","two","three")}
|
||||
$ofoo->foo("one $foo","two","three") {$ofoo->foo("one $foo","two","three")}
|
||||
$ofoo->foo("one $foo","two $foo","three") {$ofoo->foo("one $foo","two $foo","three")}
|
||||
$ofoo->foo("one","two","three") {$ofoo->foo("one","two","three","four")}
|
||||
$ofoo->foo('one $foo','two $foo','three') {$ofoo->foo('one $foo','two $foo','three')}
|
||||
$ofoo->foo('one')|upper {$ofoo->foo('one')|upper}
|
||||
|
||||
|
||||
nested object nfoo
|
||||
------------------
|
||||
|
||||
|
||||
$nfoo->ofoo->blah {$nfoo->ofoo->blah}
|
||||
$nfoo->ofoo->foo('bar') {$nfoo->ofoo->foo('bar')}
|
||||
$nfoo->ofoo->foo("bar") {$nfoo->ofoo->foo("bar")}
|
||||
$nfoo->ofoo->foo("$foo bar") {$nfoo->ofoo->foo("$foo bar")}
|
||||
$nfoo->ofoo->foo("one","two") {$nfoo->ofoo->foo("one","two")}
|
||||
$nfoo->ofoo->foo("one","two","three") {$nfoo->ofoo->foo("one","two","three")}
|
||||
$nfoo->ofoo->foo("one $foo","two","three") {$nfoo->ofoo->foo("one $foo","two","three")}
|
||||
$nfoo->ofoo->foo("one $foo","two $foo","three") {$nfoo->ofoo->foo("one $foo","two $foo","three")}
|
||||
$nfoo->ofoo->foo("one","two","three") {$nfoo->ofoo->foo("one","two","three","four")}
|
||||
$nfoo->ofoo->foo('one $foo','two $foo','three') {$nfoo->ofoo->foo('one $foo','two $foo','three')}
|
||||
$nfoo->ofoo->foo('one')|upper {$nfoo->ofoo->foo('one')|upper}
|
||||
|
||||
|
||||
function ffoo
|
||||
-------------
|
||||
|
||||
ffoo var="foo" {ffoo var="foo"}
|
||||
ffoo var="foo" var2="blah" {ffoo var="foo" var2="blah"}
|
||||
ffoo var=$foo {ffoo var=$foo}
|
||||
ffoo var=truey {ffoo var=truey}
|
||||
ffoo var=$foo|upper {ffoo var=$foo|upper}
|
||||
ffoo var="foo"|upper {ffoo var="foo"|upper}
|
||||
ffoo var=$ofoo->foo("$foo bar") {ffoo var=$ofoo->foo("$foo bar")}
|
||||
ffoo|upper var=$foo {ffoo|upper var=$foo}
|
||||
|
||||
|
||||
|
||||
section loop over sfoo
|
||||
----------------------
|
||||
|
||||
{section name=sec loop=$sfoo}
|
||||
$sfoo[sec] {$sfoo[sec]}
|
||||
$sfoo[sec.index] {$sfoo[sec.index]}
|
||||
$sfoo[sec.index_next] {$sfoo[sec.index_next]}
|
||||
$sfoo[sec.index_prev] {$sfoo[sec.index_prev]}
|
||||
$sfoo[sec.iteration] {$sfoo[sec.iteration]}
|
||||
$sfoo[sec.first] {$sfoo[sec.first]}
|
||||
$sfoo[sec.last] {$sfoo[sec.last]}
|
||||
$sfoo[sec.rownum] {$sfoo[sec.rownum]}
|
||||
$sfoo[sec.loop] {$sfoo[sec.loop]}
|
||||
$sfoo[sec.total] {$sfoo[sec.total]}
|
||||
$sfoo[sec.show] {$sfoo[sec.show]}
|
||||
$sfoo[sec]|upper {$sfoo[sec]|upper}
|
||||
$sfoo[sec]|upper|spacify {$sfoo[sec]|upper|spacify}
|
||||
$sfoo[sec]|spacify:"^^" {$sfoo[sec]|spacify:"^^"}
|
||||
$sfoo[sec]|@count {$sfoo[sec]|@count}
|
||||
$sfoo[sec]|default:"no" {$sfoo[sec]|default:"no"}
|
||||
$sfoo[sec]|truncate:6:"...":true {$sfoo[sec]|truncate:6:"...":true}
|
||||
|
||||
$smarty.section.sec.index {$smarty.section.sec.index}
|
||||
|
||||
{section name=outer loop=$FirstName}
|
||||
{if %outer.index% is odd by 2}
|
||||
{%outer.rownum%} . {$FirstName[outer]} {$LastName[outer]}
|
||||
{else}
|
||||
{%outer.rownum%} * {$FirstName[outer]} {$LastName[outer]}
|
||||
{/if}
|
||||
{sectionelse}
|
||||
none
|
||||
{/section}
|
||||
|
||||
An example of section looped key values:
|
||||
if statement parse test
|
||||
-----------------------
|
||||
|
||||
{section name=sec1 loop=$contacts}
|
||||
phone: {$contacts[sec1].phone}<br>
|
||||
fax: {$contacts[sec1].fax}<br>
|
||||
cell: {$contacts[sec1].cell}<br>
|
||||
if $foo {if $foo}{/if}(end)
|
||||
if $foo eq "bar" {if $foo eq "bar"}foo is bar{/if}(end)
|
||||
if is_array($foo) {if is_array($foo)}foo is array{else}foo is not array{/if}(end)
|
||||
if $foo gt 4 {if $foo gt 4}$foo is gt 4{/if}(end)
|
||||
if ($foo gt 4) {if ($foo gt 4)}$foo is gt 4{/if}(end)
|
||||
if ( $foo gt 4 ) {if ( $foo gt 4 )}$foo is gt 4{/if}(end)
|
||||
if $foo and not $bar {if $foo and not $bar}foo and not bar{/if}(end)
|
||||
if !$bfoo {if !$bfoo}not bfoo{else}bfoo{/if}(end)
|
||||
if 4 is div by 4 {if 4 is div by 4}div by 4{else}not div by 4{/if}(end)
|
||||
if 3 is div by 4 {if 3 is div by 4}div by 4{else}not div by 4{/if}(end)
|
||||
if 3 is div by 4 or ( 3 eq 3 ) {if 3 is div by 4 or ( 3 eq 3 )}blah{/if}(end)
|
||||
if (3 is div by 4) or ( 3<="bah"|upper ) {if (3 is div by 4) or ( 3<="bah"|upper )}woohoo{/if}(end)
|
||||
if in_array("my $bar", $afoo) {if in_array("my $bar", $afoo)}is in{else}is not in{/if}(end)
|
||||
if $ofoo->foo() {if $ofoo->foo()}is in{else}is not in{/if}(end)
|
||||
if in_array($ofoo->foo("two"), $afoo) {if in_array($ofoo->foo("two"), $afoo)}is in{else}is not in{/if}(end)
|
||||
|
||||
$smarty variable access
|
||||
-----------------------
|
||||
|
||||
$smarty.now {$smarty.now}
|
||||
$smarty.const._MY_CONST {$smarty.const._MY_CONST}
|
||||
|
||||
block function
|
||||
--------------
|
||||
|
||||
{reverse}
|
||||
This is my block of text.
|
||||
{/reverse|upper}
|
||||
|
||||
misc syntax, try to break
|
||||
-------------------------
|
||||
|
||||
$foo|spacify:"|" {$foo|spacify:"|"}
|
||||
$foo|spacify:"|"|upper {$foo|spacify:"|"|upper}
|
||||
$foo|spacify:"$foo"|upper|default:"|" {$foo|spacify:"$foo"|upper|default:"|"}
|
||||
|
||||
{section name=sec loop=$sfoo}
|
||||
$ofoo->foo($sfoo[sec],$sfoo[sec]|spacify:"^^",$sfoo[sec]|truncate:6:"...":true) {$ofoo->foo($sfoo[sec],$sfoo[sec]|spacify:"^^",$sfoo[sec]|truncate:6:"...":true)}
|
||||
$nfoo->ofoo->foo($sfoo[sec],$sfoo[sec]|spacify:"^^",$sfoo[sec]|truncate:6:"...":true) {$nfoo->ofoo->foo($sfoo[sec],$sfoo[sec]|spacify:"^^",$sfoo[sec]|truncate:6:"...":true)}
|
||||
{/section}
|
||||
<p>
|
||||
|
||||
testing strip tags
|
||||
{strip}
|
||||
<table border=0>
|
||||
<tr>
|
||||
<td>
|
||||
<A HREF="{$SCRIPT_NAME}">
|
||||
<font color="red">This is a test </font>
|
||||
</A>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
{/strip}
|
||||
ffoo|spacify:"|"|upper var="lalala" {ffoo|spacify:"|"|upper var="lalala"}
|
||||
ffoo|spacify:" my spaces "|upper var="lalala" {ffoo|spacify:" my spaces "|upper var="lalala"}
|
||||
ffoo|spacify:"!@#$%^&*()_+=-\|]["|upper var="lalala" {ffoo|spacify:"!@#$%^&*()_+=-\|]["|upper var="lalala"}
|
||||
|
||||
</PRE>
|
||||
{config_load file=test.conf section=foo}
|
||||
|
||||
This is an example of the html_select_date function:
|
||||
if !$nfoo->ofoo->foo("blah blah") {if !$nfoo->ofoo->foo("blah blah")}not blah{else}blah{/if}(end)
|
||||
|
||||
<form>
|
||||
{html_select_date start_year=1998 end_year=2010}
|
||||
</form>
|
||||
"static"|upper {"static"|upper}
|
||||
|
||||
This is an example of the html_select_time function:
|
||||
{foreach item="fofoo" from=$afoo}
|
||||
|
||||
<form>
|
||||
{html_select_time use_24_hours=false}
|
||||
</form>
|
||||
DEBUG FOREACH: {$fofoo}
|
||||
|
||||
This is an example of the html_options function:
|
||||
{/foreach}
|
||||
|
||||
<form>
|
||||
<select name=states>
|
||||
{html_options values=$option_values selected=$option_selected output=$option_output}
|
||||
</select>
|
||||
</form>
|
||||
END SMARTY SMOKE TEST
|
||||
|
||||
{include file="footer.tpl"}
|
||||
|
Reference in New Issue
Block a user