smarty的问题---变量无法在html中显示

php中文网
发布: 2016-06-23 14:13:32
原创
1147人浏览过

Smarty HTML

1.php
include_once("libs/Smarty.class.php");
$smarty=new Smarty();

$smarty->template_dir="templates";
$smarty->compile_dir="compile";
$smarty->config_dir="config";
$smarty->cache_dir="cache";

$smarty->left_delimiter="{";
$smarty->right_delimiter="}";
?>

2.php
include ("smarty_include.php");
$name="this is an apple!";
$smarty->assign("abc",$name);
$smarty->display("index.html");
?>

index.html

    
        

 {$abc} 

无涯·问知
无涯·问知

无涯·问知,是一款基于星环大模型底座,结合个人知识库、企业知识库、法律法规、财经等多种知识源的企业级垂直领域问答产品

无涯·问知 40
查看详情 无涯·问知

    


index里面的$abc无法显示出$name的值
2.php里可以显示出this is an apple!
请问这是为什么

回复讨论(解决方案)

下载最新的Smarty:http://smarty.php.net/ 当前最新版本:2.6.18 解压后将目录中的libs目录重命名为smarty,复制到你的网站目录,同时在网站根目录下建立templates和templates_c两个目录 建立test.php,内容如下: <?php include_once('./Smarty/Smarty.class.php');$smarty = new Smarty(); $smarty -> template_dir = "./templates"; //模板存放目录 $smarty -> compile_dir = "./templates_c"; //编译目录 $smarty -> left_delimiter = "{{"; //左定界符 $smarty -> right_delimiter = "}}"; //右定界符 $smarty -> assign('test','OK'); $smarty -> display('test.html'); ?> 给templates_c权限755 在templates目录下新建test.html: <html> <head> </head> <body> {{$test}} </body> </html> 打开test.php,如果看到OK就说明你的smarty安装成功了! 
登录后复制

test.php显示ok,但是test.html却是{{$test}},没有显示值,和之前没有区别。我想知道html文件里怎么显示{{$test}}

确认smarty已经正确的配置好...不知道你的smarty是个什么版本

test.php显示ok,但是test.html却是{{$test}},没有显示值,和之前没有区别。我想知道html文件里怎么显示{{$test}}
有没设置缓存目录的权限

3.1.13和2.6.27版本,都试过了.

HTML速学教程(入门课程)
HTML速学教程(入门课程)

HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号