数字化技能提升教程,数字化时代生存宝典

数字化百科 / 词条 / QuickSkin语法介绍

QuickSkin语法介绍

查看全部词条命名空间:Main

先来看一个简单的例子,让我们了解下QuickSkin是如何工作的。
下面我们来编写一个能够生成我们想要的效果的HTML代码。



Hello World!




接着我们来做激动人心的步骤,即将内容和设计分离。我们将用占位符来替代HTML内所有的动态内容,这些内容被赋上了一个独特的名字和围上了属于自己的标签。这样在以后的程序里我们就能够识别它。标题Hello world!被一个叫做TITLE的占位符替代了,并被嵌入到了一个波形符号内。这样模板解析器就能够识别它{TITLE}.
HTML的模板 (hello_world.tpl.html)是:


{TITLE}




为了为这模板装上内容,我们要做的是:
#载入 SmartTemplate Class (类)
#初始化一个SmartTemplate 解析器对象
#为内容赋上相关占位符
#处理模板
#打印结果
下面的PHP脚本将完成这些步骤(hello_world.php)。

require_once “class.smarttemplate.php”;
$page=new SmartTemplate(”hello_word.tpl.html”);
$page->assign(’TITLE’,'Hello world!’);
$page->output( );
?>

就这些,我们的第一个Hello World 例子就完工了。

基本函数:


  • – set()

  • – addtpl()

  • – assign()

  • – append()

  • – use_cache()

  • – result()

  • – output()

  • – debug()

  • – getContents()


以上函数的使用说明:

  • – set() 语法结构: set ( 模板中变量, 内容 ) 作用:为一模板属性赋上内容,可以是字符串但不可以是数组。


例子:

$template = new QuickSkin('template.html');
$template->set( 'reuse_code', true );
$template->set( 'template_dir', _skins/ );
$template->set( 'temp_dir', _skins_tmp/ );
$template->set( 'cache_dir', _skins_cache/ );
$template->set( 'cache_lifetime', 200 );
$template->output();

?>


  • – addtpl() 语法结构: addtpl(模板中变量, 内容 ) 作用:为主模板附加一个模板。主要用于横幅广告,右边栏,注册框或会员菜单等等。所有的主模板函数也适合子模板函数。


例子:

$template = new QuickSkin('template.html');
$text = 'Sample Text';
$template->assign( 'TITLE', $text );
$template->addtpl( 'sponsors', 'default/poweredby.htm' );
$template->output();
?>

Template (template.html):

{TITLE}
{sponsors}