Công cụ thành viên

Công cụ trang web


programming4:template-engine

Đây là một phiên bản cũ của tài liệu!


PHP Template Engine

Ở các phiên bản trước NukeViet 4.4 chúng tôi sử dụng Xtemplate để tách html và PHP

Từ phiển bản 4.4 Chúng tôi xây dựng giao diện mới dựa trêm Smarty, và chuyển dần từ Xtemplate sang Smarty 3

Tài liệu hướng dẫn sử dụng Smarty 3: https://www.smarty.net/docs/en/

Chuyển đổi cách viết từ Xtemplate sang Smarty

Với Xtemplate code PHP

    $xtpl = new XTemplate($layout_file, NV_ROOTDIR . '/themes/' . $global_config['module_theme'] . '/layout');
    $xtpl->assign('MODULE_CONTENT', $contents);    
    return $xtpl->text('main');

Chuyển sang Smarty

    $smarty = new Smarty();
    $smarty->setTemplateDir(NV_ROOTDIR . '/themes/' . $global_config['module_theme'] . '/layout');
 
    $smarty->assign('MODULE_CONTENT', $contents);        
    return $smarty->fetch($layout_file);

Với Xtemplate code HTML

<!-- BEGIN: main -->
{FILE "header_only.tpl"}
	{MODULE_CONTENT}
{FILE "footer_only.tpl"}
<!-- END: main -->

Chuyển sang Smarty

{include file='header_only.tpl'} 
{$MODULE_CONTENT}
{include file='footer_only.tpl'}
programming4/template-engine.1524034645.txt.gz · Sửa đổi lần cuối: 2018/04/18 13:57 bởi vuthao