Get Smarty

Donate

Donate Bitcoin Bitcoin
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:

Check reviews of PHP Web Hosting, compatible with Smarty Templates

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'));

// передача строки из базы данных (напр. ADODB)
$sql = 'select id, name, email from contacts where contact ='.$id;
$smarty->assign('contact', $db->getRow($sql));
?>

   

Обращаемся к переменным из шаблона


{* переменные чувствительны к регистру, как и в PHP *}
{$Name}
{$Address}
{$city}
{$state}

{$contact.id}, {$contact.name},{$contact.email}

   

Для более сложных назначений массивов см. {foreach} и {section}

См. также assign_by_ref(), get_template_vars(), clear_assign(), append() и {assign}

Comments
No comments for this page.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Author:
Email: (not shown)
What is 10 plus 17? (Are you human?)

Sponsors [info]

Cheap Website Hosting @hostdone.com
email marketing @ActiveCampaign
I.T Certification Exams @pass-guaranteed.com
Certification Practice Tests @firsttrycertify.com
Certification Practice Exam Questions @ace-it-certifications.com
Broadband Providers @broadbandproviders.co.uk
bulk email software @americaint.com
ASP.NET hosting @aspnethosting.co.uk