Get Smarty

Donate

Paypal

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Sites Using Smarty

Advertisement

Name

assign() — テンプレートに値を割り当てます。

説明

void assign(mixed var);
void assign(string varname,
            mixed var);

テンプレート変数名/値のペアを明示的に指定するか、それらが格納された連想配列を指定します。

Example 13.3. assign()


<?php
// 名前/値のペアを渡します
$smarty->assign('Name', 'Fred');
$smarty->assign('Address', $address);

// 連想配列を渡します
$smarty->assign(array('city' => 'Lincoln', 'state' => 'Nebraska'));

// 配列を渡します
$myArray = array('no' => 10, 'label' => 'Peanuts');
$smarty->assign('foo',$myArray);

// データベース (例: adodb) の行を渡します
$sql = 'select id, name, email from contacts where contact ='.$id;
$smarty->assign('contact', $db->getRow($sql));
?>

テンプレートの内容


{* 変数は、php と同様に大文字小文字を区別することに注意しましょう *}
{$Name}
{$Address}
{$city}
{$state}

{$foo.no}, {$foo.label}
{$contact.id}, {$contact.name},{$contact.email}


より複雑な配列の割り当てに関しては、 {foreach} および {section} を参照してください。

assign_by_ref()get_template_vars()clear_assign()append() および {assign} も参照してください。

Comments
No comments for this page.

Advertisement

Sponsors [info]

Sponsors