关于我们

质量为本、客户为根、勇于拼搏、务实创新

< 返回新闻公共列表

ecshop Smarty引擎如何获得模版路径

发布时间:2019-09-12 09:45:37

每次都搞了头大,搞清楚方法。一切都清晰。

思路:我们先输出模版文件在哪个文件夹。然后再去修改相应模版。

//var_dump($smarty->template_dir);//输出模版路径
//break;



1. 写一个配置文件smarty.ini.php:


<?PHP

//引用类文件?

require 'smarty/Smarty.class.php';

$smarty = new Smarty;

//$smarty=new Smarty;

//设置各个目录的路径,这里是安装的重点

$smarty->template_dir="templates/templates";

$smarty->compile_dir="templates/templates_c";

$smarty->config_dir="templates/config";

$smarty->cache_dir="templates/cache";

//smarty模板有高速缓存的功能,如果这里是true的话即打开caching,但是会造成网页不立即更新的问题,当然也可以通过其他的办法解决

$smarty->caching=false;

?>




2. 在使用模板的index.php文件中:


<?php

    include "smarty.ini.php";

    $title="Smarty-Learn-Test";

    $content="Smarty_content哈哈";

    $auth="MarcoFly";

    $website="www.MarcoFly.com";

    $smarty->assign("title",$title);

    $smarty->assign("content",$content);    

    $smarty->assign("auth",$auth);

    $smarty->assign("website",$website);

    $smarty->display("index.html");

?>


相应的index.html文件:


<!DOCTYPE HTML>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>{$title}</title>

</head>

<body>

<p>内容:{$content}</p>

<p>作者:{$auth}</p>

<p>网址:{$website}</p>

</body>

</html>


/template/Home/Zkeys/PC/Static