当前位置: 博客首页 >> PHP >> 阅读正文

学习smarty第一天

作者: 郑晓 分类: PHP 发布于: 2011-11-15 23:22 浏览:4,001 没有评论


从今天开始学习smarty模板技术了,其实应该是第二天了,昨天晚上学习smarty的基本配置。再其实,以前学过,都忘了……….

今天主要学习的是smarty中$smarty->assign()和$smarty->display()两个函数的简单使用,以及简单的{section}和{foreach}循环。 smarty简单配置文件: <?phpinclude './smarty/Smarty.class.php'; $smarty = new smarty(); $smarty->config_dir = 'smarty/config_file.class.php'; $smarty->caching = false; $smarty->cache_dir = './cache'; $smarty->cache_lifetime = 0; $smarty->template_dir = './tpl'; $smarty->complate_dir = './templates_c'; $smarty->left_delimiter = '{'; $smarty->right_delimiter = '}'; ?> index.php: <?php include 'smarty_inc.php'; $content = '学习smarty'; $new[] = array('new_name'=>'新闻第一条','date'=>'2011-11-15'); $new[] = array('new_name'=>'新闻第二条','date'=>'2011-11-15'); $new[] = array('new_name'=>'新闻第三条','date'=>'2011-11-15'); $new[] = array('new_name'=>'新闻第四条','date'=>'2011-11-15'); $new[] = array('new_name'=>'新闻第五条','date'=>'2011-11-15');</p> <p>$smarty->assign('new',$new); $smarty->display('index.htm'); ?> index模板文件:</p> <p> {foreach from=$new key=k item=v} </p> <p> foreach中,from是要循环的数组变量,item是循环时当前的变量值,key是循环时当前的键值,name只是一个标记。换成php中,应该可以这样表示吧?foreach( from as key =>item){}

       

本文采用知识共享署名-非商业性使用 3.0 中国大陆许可协议进行许可,转载时请注明出处及相应链接。

本文永久链接: https://www.zh30.com/the-first-day-of-learning-smarty.html

发表评论

change vcode