smarty模板变量赋值并输出

Original 2019-06-01 16:05:39 154
abstract:$name = 'chao'; $smarty->assign('name',$name); $courses = ['html5', 'css3']; $smarty->assign('courses', $courses); $book&n
$name = 'chao';
$smarty->assign('name',$name);

$courses = ['html5', 'css3'];
$smarty->assign('courses', $courses);

$book = ['name'=>'PHP开发','price'=>69, 'publish'=>'2018-04-22'];
$smarty->assign('book', $book);



$books = [
    ['name'=>'PHP开发','price'=>69, 'publish'=>'2018-04-22'],
    ['name'=>'MySQL性能分析', 'price'=>39, 'publish'=>'2017-10-10']
    ];
$smarty->assign('books', $books);


class Test
{
    public $site = 'www.baidu.com';
    public function welcome()
    {
        return '访问的网址是:'.$this->site;
    }
}
$test = new Test;
$smarty->assign('test',$test);
<h3>我是: {$name}</h3>
<hr>

<p>前端课程: {$courses[0]},{$courses[1]}</p>

<p>书名:《{$book.name}》,价格:{$book['price']}元,出版时间:{$book.publish}</p>

<p>书名:《{$books.1.name}》,价格:{$books[1]['price']}元,出版时间:{$books.1.publish}</p>

<p>我是:{$test->site}, {$test->welcome()}</p>


Correcting teacher:天蓬老师Correction time:2019-06-03 09:33:58
Teacher's summary:任何一个模板引擎最基本的功能之就是输出模板变量, 当然还要支持流程控制

Release Notes

Popular Entries