示例代码: require(libs/Smarty.class.php); $tpl=new Smarty(); $tpl->template_dir=./templates/; $tpl->compile_dir=./templates_c; $tpl->config_di示例代码: require(libs/Smarty.class.php); $tpl=new Smarty(); $tpl->template_dir=./templates/; $tpl->compile_dir=./templates_c; $tpl->config_dir=./config/; $tpl->cache_dir=./cache/; $tpl->left_delimiter=<{; $tpl->right_delimiter=}>; ob_start(); //打开输出缓...
include_once("smarty/Smarty.class.php");$smarty=new Smarty();$smarty->config_dir="smarty/Config_File.class.php";$smarty->caching=false;$smarty->template_dir="./templates";$smarty->compile_dir="./templates_c";$smarty->cache_dir="./smarty_cache";$smarty->left_delimiter="{";$smarty->right_delimiter="}";?>3、编写php文件 index.phpinclude("smarty_inc.php");$name[]=array("name"=>"新闻第一条","date"=>"200...
简易的smarty 对新手理解smarty有帮助 源于itcast韩顺平老师smarty第2、3讲 class MyMiniSmarty{ public $template_dir = "./templates"; public $complie_dir = "./templates_c"; public $tpl_vars = array(); public function assign($tpl_var,$val = NULL){ if(!empty($tpl_var)){ $this->tpl_vars[$tpl_var] = $val; } } public function display($tpl_file){ $tpl_file_path = $this->template_...
<{$content}> 保存在 templates 目录中。 5、新建文件模板配置文件: config.phpinclude "../libs/Smarty.class.php";$NowPathArray=explode("test",str_replace("\\","/",dirname(__FILE__))) ;@define("root_path", $NowPathArray[0]);@define('__SITE_ROOT', root_path."test");$tpl = new Smarty();$tpl->template_dir = __SITE_ROOT . "/templates/";$tpl->compile_dir = __SITE_ROOT . "/templates_c/";$tpl->config_dir = __...
<?phpfunction SmartyLen($params){extract($params);$len=strlen($text);$max=$length;for ($i=0;$i<$length;$i++){ $chr=substr($text,$i,1); if(ord($chr)>0x80)//字符是中文 { $length++; $i++; $len--; }}$str=substr($text,0,$length);if($len>$max)$str.="...";Return $str;} 注册函数 $smarty->register_function(len,"SmartyLen");模板调用...
{if $pageCount > 1} {foreach item=i from=$pagerList} {if $pageNum eq $i} {$i} {else} {$i}{/if} {/foreach} {if $pageNum eq 1} 上一页{else} 上一页{/if} {if $pageNum eq $pageCount } 下一页{else} 下一页{/if} {if $pageNum eq 1} 首页{else} 首页{/if} {if $pageNum eq $pageCount} 最后一页{else} 最后一页{/if} {/if} (共{$pageCount}页)
本文介绍了在smarty中调用js时,整个页面不会显示的解决方法,方法很简单,却很实用,有需要的朋友,不要错过。在smarty中包含js时,整个页面就不会显示,如何解决呢?办法很简单,如下: 把模板页面中的js代码复制到外面新建的文件夹中,然后再包含到模板页中即可。 例如: {popup_init src="css/commen.js"} 轻松转换后,问题解决了。
这篇文章主要介绍了smarty中英文多编码字符截取乱码问题解决方法,涉及到对原有smartTruncate的修改,非常具有实用价值,需要的朋友可以参考下本文实例讲述了smarty中英文多编码字符截取乱码问题解决方法,分享给大家供大家参考。具体方法如下:一般网站页面的显示都不可避免的会涉及子字符串的截取,这个时候truncate就派上用场了,但是它只适合英文用户,对与中文用户来说,使用 truncate会出现乱码,而且对于中文英文混合串来说,截...
<{foreach item=i from=$abc}><{foreach item=j from=$def}><{/foreach}><{/foreach}>以上方法,简单实用。 不过,有些应用场景中,还是要用到<{assign}>方法,这个大家可以找点文章,好好研究下。
{section name=total loop=100}{$smarty.section.total.index+1} //当前的索引{$smarty.section.total.iteration} //用于显示循环的次数{/section}还可以这样:{assign var=i value=0}{section name=total loop=100}{assign var=i value=$i+1} {$i} //使用assign的方式赋值{/section}输出结果: 1 2 3 4 5 ... ... 100 另外,介绍下在smarty中使用php函数的方法。 在smarty模板中,如果使用php函数,只有一个参数的函数比如说去空白...
本文介绍下,smarty模板引擎中,生成静态页的关键代码,有需要的朋友,参考下吧。在smarty中有一个获取模板页内容方法fetch(), 它的声明原形为:代码说明: 第一个参数为模板名称, 第二个参数为缓存的id, 第三个参数为编译id, 第四个参数为是否显示模板内容。 生成静态页,就需要用到这个方法。fetch(’模板名称.tpl’, null, null, false); //将内容写入至一个静态文件 $fp=fopen(’news.html’,'w’); fwrite($fp,$content); fc...
/*** smarty模板引擎中使用php函数* by bbs.it-home.org*/require 'libs/Smarty.class.php'; $smarty=new Smarty; $smarty->compile_check=true; $smarty->debugging=true; $str1='testtesttesttest'; $str2='this is a'; $str3='脚本 学堂 bbs.it-home.org'; $str4='this is four'; $smarty->assign('str1',$str1); $smarty->assign('str2',$str2); $smarty->assign...
{$smarty.now|date_format:"%Y-%m-%d %H:%M:%S"}2.{$smarty.const} 可以直接访问PHP常量. 例如{$smarty.const._MY_CONST_VAL}3.{$smarty.capture} 可以通过 {capture}..{/capture}结构 截取的输出可以使用{$smarty} 变量访问. 4.{$smarty.config} {$smarty}变量 可以访问已经加载的config变量 例如 {$smarty.config.foo}就可以表示 {#foo#} 5.{$smarty.section}, {$smarty.foreach} {$smarty} 变量可以访问section和foreach循环...
本文介绍了php中使用smarty模板引擎生成静态页面的方法,以及php实现文章分页的实现代码,需要的朋友参考下。 例子,php中smarty生成静态页、文章内分页代码。专题:php分页代码原理',$content);$num = 0;foreach ($temp as $key => $val ) {$num++;$pagenav = '';if ($key == 0) {$file_name = '../html/'.$article_id.'.html';} else {$file_name = '../html/'.$article_id.'_'.($key+1).'.html';}for ($i=1;$i{$i} ";}else{if (...
include_once("smarty.class.php");class smartyproject extendssmarty{function __construct() { $this->config_dir="smarty/smarty/config_file.class.php"; $this->caching=false; $this->template_dir = "smarty/templates/"; $this->cache_dir = "smarty/smarty_cache/"; $this->left_delimiter = "{"; $this->right_delimiter = "}"; }}?>2,adodb,连接数据库类:class conndb{var $dbtype;var $host;var $user;var $pwd;v...