・php詳細
$name = "";
$html->assign("name",$name);
・tpl詳細
デフォルト文<br>
{$name|default:"hoge"}<br>
・結果
デフォルト文<br>
hoge<br>
------------------------------
・php詳細
$lang = array("php","jsp","cgi",array("c","c++"));
$html->assign("lang",$lang);
・tpl詳細
単純配列文<br>
php : {$lang[0]}<br>
jsp : {$lang[1]}<br>
cgi: : {$lang[2]}<br>
c : {$lang[3][0]}<br>
c++ : {$lang[3][1]}<br>
・結果
単純配列文<br>
php : php<br>
jsp : jsp<br>
cgi: : cgi<br>
c : c<br>
c++ : c++<br>
------------------------------
・php詳細
$data = array("name"=>"hoge","tel"=>"000-0000-0000","mail"=>array("hoge@hoge.com","home"=>"hogehoge@hoge.com"));
$html->assign("data",$data);
・tpl詳細
連想配列文<br>
name : {$data.name}<br>
tel : {$data.tel}<br>
mail : {$data.mail[0]}<br>
mail : {$data.mail.home}<br>
・結果
連想配列文<br>
name : hoge<br>
tel : 000-0000-0000<br>
mail : hoge@hoge.com<br>
mail : hogehoge@hoge.com<br>
------------------------------
・php詳細
class MyClass {
public $name;
private $tel;
public function __construct($name,$tel){
$this->name = $name;
$this->tel = $tel;
}
public function getTel(){return $this->tel;}
}
$obj = new MyClass("hoge","000-000-0000");
$html->assign("obj",$obj);
・tpl詳細
オブジェクト文<br>
name : {$obj->name}<br>
tel : {$obj->getTel()}<br>
・結果
オブジェクト文<br>
name : hoge<br>
tel : 000-000-0000<br>
------------------------------
・php詳細
define("NO",100);
・tpl詳細
PHP定数文<br>
{$smarty.const.NO}<br>
・結果
PHP定数文<br>
100<br>
------------------------------
・tpl詳細
現在のタイム文<br>
{$smarty.now}<br>
・結果
現在のタイム文<br>
1168417541<br>
------------------------------
・tpl詳細
実行中のテンプレート名文<br>
{$smarty.template}<br>
・結果
実行中のテンプレート名文<br>
hogehoge.tpl<br>
------------------------------
・tpl詳細
Smartyのバージョン情報文<br>
{$smarty.version}<br>
・結果
Smartyのバージョン情報文<br>
x.x.x<br>
------------------------------
・php詳細
$_GET['id'] = "'<id&pass>'+hoge";
$_POST['id'] = "'<id&pass>'+hoge";
$_REQUEST['id'] = "'<id&pass>'+hoge";
・tpl詳細
GET情報文<br>
{$smarty.get.id|escape}<br>
<br>
POST情報文<br>
{$smarty.post.id|escape:"htmlall"}<br>
<br>
REQUEST情報文<br>
{$smarty.request.id|escape:"javascript"}<br>
・結果
GET情報文<br>
'<id&pass>'+hoge<br>
POST情報文<br>
'<id&pass>'+hoge<br>
REQUEST情報文<br>
\'<id&pass>\'+hoge<br>
------------------------------
・php詳細
$lang = array("php","jsp","cgi",array("c","c++"));
$html->assign("lang",$lang);
・tpl詳細
単純配列カウント数文<br>
{$lang|@count}<br>
・結果
単純配列カウント数文<br>
4<br>
------------------------------
・php詳細
$data = array("name"=>"hoge","tel"=>"000-0000-0000","mail"=>array("hoge@hoge.com","home"=>"hogehoge@hoge.com"));
$html->assign("data",$data);
・tpl詳細
連想配列カウント数文<br>
{$data|@count}<br>
・結果連想配列カウント数文<br>
3<br>
------------------------------
・tpl詳細
日付文<br>
{$smarty.now|date_format:"%Y年%m月%d日 %H時:%M分:%S秒 %A"}<br>
・結果
日付文<br>
2007年01月10日 17時:25分:41秒 Wednesday<br>
------------------------------
・php詳細
$lang = array("php","jsp","cgi",array("c","c++"));
$html->assign("lang",$lang);
・tpl詳細
if文<br>
{if count($lang) > 2}
$langは2より大きいです<br>
{/if}
・結果
if文<br>
$langは2より大きいです<br>
------------------------------
・php詳細
$array_1 = array("name"=>"hoge","tel"=>"000-0000-0000","age"=>20);
$html->assign("array_1",$array_1);
・tpl詳細
foreach文<br>
{foreach from=$array_1 key="key" item="value" name="loop"}
KEY {$key} : VALUE {$value}<br>
{/foreach}
・結果
foreach文<br>
KEY name : VALUE hoge<br>
KEY tel : VALUE 000-0000-0000<br>
KEY age : VALUE 20<br>
------------------------------
・php詳細
$array_2 = array("hogehoge","111-1111-1111",25);
$array_3 = array("testtest","222-2222-2222",20);
$html->assign("array_2",$array_2);
$html->assign("array_3",$array_3);
・tpl詳細
section文<br>
{section name="data" loop=$array_2}
{$array_2[data]}<br>
{$array_3[data]}<br>
{/section}
・結果
section文<br>
hogehoge<br>
testtest<br>
111-1111-1111<br>
222-2222-2222<br>
25<br>
20<br>
------------------------------
・tpl詳細
mail文<br>
{mailto address="hoge@hoge.com" encode="hex"}<br>
・結果
mail文<br>
<a href="mailto:%68%6f%67%65@%68%6f%67%65.%63%6f%6d" >hoge@hoge.com</a><br>
------------------------------
PR