Smarty模板配置文件,及详细配置过程

本文详细介绍了如何在D:/xampp/htdocs目录下配置Smarty模板引擎,并通过实例演示了如何使用Smarty展示网页内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

路径很关键。

可以不确定的时候先用echo 打印出来,看看路径是否正确。

我的服务器目录是D:/xampp/htdocs;

文件目录如下:



 config.php内容如下

<?php 
	define('BASE_PATH',$_SERVER['DOCUMENT_ROOT']);//D:/xampp/htdocs
	define('SMARTY_PATH', '/SmartyTest/Smarty/');//D:/xampp/htdocs/SmartyTest/Smarty/
	require BASE_PATH.SMARTY_PATH.'Smarty.class.php';
	$smarty=new Smarty();
	$smarty->template_dir='./Smarty/templates/';
	$smarty->compile_dir='./Smarty/templates_c/';
	$smarty->config_dir='./Smarty/configs/';
	$smarty->cache_dir='./Smarty/cache/'
?>

 index.php的内容如下,关键要写清include的地址

<?php 
header("Content-type:text/html;charset=UTF-8");
include("Smarty/configs/config.php");//关键
$smarty->assign('title','第一个smarty程序');
$smarty->assign('content','hello world');
$smarty->display('index.html');
?>

 templates文件夹下面有一个 index.html。

<html>
<title>{$title}</title>
<body>
<p>{$content}</p>
</body>
</html>

 访问的时候输入:http://localhost/SmartyTest/index.php即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值