PHP之smarty定界符的代码使用?

版权声明:本文为郝云原创文章,未经郝云允许不得转载。 https://blog.csdn.net/haoyunyun888/article/details/82389591

所有的smarty模板标签都被加上了定界符.
默认情况下是 { 和},但它们是可被改变的.

例如,我们假定你在使用默认定界符.
smarty里,所有定界符以外的内容都是静态输出的,或者称之为不可改变.
当smarty遇到了模板标签,将尝试解释他们,然后再以恰当的方式输出 .

PHP原生格式可不可以呢,当然可以,只需配置即可?

代码:

<?php
header("content-type:text/html;charset=utf-8");
// +----------------------------------------------------------------------
// |授课名称:PHP之smarty代码之定界符的设置
// +----------------------------------------------------------------------
// | 时间:2018年9月4日20:00:04
// +----------------------------------------------------------------------
// | Author: Mr.hao 博客地址:http://blog.csdn.net/haoyunyun888
// +----------------------------------------------------------------------
//引入文件
include "Smarty.class.php";//类
$smarty=new Smarty();//实例化对象
$smarty->assign("username","师梓健");//赋值
$smarty->assign("sex","男");//赋值
$smarty->assign("address","山西临汾");//赋值
$smarty->left_delimiter = '<?php';//定义左前缀
$smarty->right_delimiter ='?>';//定义后前缀
$smarty->display('show.html');//显示

 如何访问?

<!DOCTYPE html>
<!--
定界符代码使用:
注意:前边已经设置了相应规则,所以必须按照规则走
左:<?php
右:?>
-->
<html>
    <head>
        <title>TODO supply a title</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        
         <div><?php$username?></div>
         <div><?php$sex?> </div>
         <div>{$address}</div>
    </body>
</html>

猜你喜欢

转载自blog.csdn.net/haoyunyun888/article/details/82389591