Browsing the archives for the smarty tag

使用smarty来实现网站代码简单重用

in 程序开发

在网站开发过程中,有大量显示组件是可以被重用的,最常见到的就是一些排行列表,如:最新排行,最热排行等。 代码结构: index.php class –>存放业务类 article.class.php smarty –> smarty库 template –>存放smarty模板相关 html –>模板 index.html plugins –>插件 template_c –>smarty编译目录

0 Comments

在smarty中增加类似foreach的功能自动加载数据

in 程序开发

在smarty中使用自定义插件来加载数据(见:http://blog.csdn.net/yycai/archive/2009/12/26/5083594.aspx), 在使用的时候还是感觉不够方便,灵机一动就想写成类似foreach那种标签: 第一步:在Smarty_Compiler.class.php的_compile_tag函数中增加: view plaincopy to clipboardprint? //加载 数据的开始标签 case 'load': $this->_push_tag('load'); return $this->_complie_load_start($tag_args); break; //加载数据的结束标签 case '/load': $this->_pop_tag('load'); return "<?php endforeach; endif; unset(\$_from); ?>"; break; //加载 数据的开始标签 case 'load': $this->_push_tag('load'); return $this->_complie_load_start($tag_args); break; //加载数据的结束标签 case '/load': $this->_pop_tag('load'); return "<?php endforeach; endif; unset(\$_from); ?>"; break; 第二步:增加一个方法: view plaincopy to clipboardprint? /** * 加载数据 * @param $tag_args */ function _complie_load_start($tag_args) { $key = [...]

0 Comments

Smarty缩图函数

in 程序开发

http://www.cerdmann.com/thumb/ 下载: function.thumb.php <?php /* * Smarty plugin "Thumb" * Purpose: creates cached thumbnails * Home: http://www.cerdmann.com/thumb/ * Copyright (C) 2005 Christoph Erdmann * * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either [...]

0 Comments

Smarty高级特性 – 用户自定义函数使用 SMARTY:: register_function;

in 程序开发

Smarty 高级 特性 – 用户自定义函数 使用 SMARTY:: register_function; 前言: 很久不用smarty了,因为大多数项目都是比较轻量型的。前段时间 笔者接了个还算可以的项目,下面有几个程序员 ,与一个美工组为项目团队。为了做快速的布署应用 ,也为了小组成员能形成一个统一的view层的控制,选择了smarty。发现smarty果然还是那么的强大,那么的很黄很暴力。 作者:无喱头

0 Comments

smarty缓存使用技巧

in 程序开发

一、使用缓存 要开启smarty的缓存,只需将caching设为true,并指定cache_dir即可. 使用cache_lefetime指定 缓存生存时间,单位为秒 要对相同页面生成多个不同的缓存,在display或fetch中加入第二参数cache_id, 如$smarty->display('index.tpl',$my_cache_id);此特性可用于对不同的$_GET进行不同的缓存 二、清除缓存 clear_all_cache();//清除所有缓存 clear_cache('index.tpl');// 清除index.tpl的缓存 clear_cache('index.tpl',cache_id);//清除指定id的缓存

0 Comments

smarty模板引擎中插件的使用实例

in 程序开发

在libs/plugins目录里新建一个function.html_options_list.php文件,内容如下: ---------------------------------------------------------------------------------------------------------- function smarty_function_html_options_list($params, &$smarty) { require_once $smarty->_get_plugin_filepath('shared','escape_special_chars'); $name = null; $text = null; $value = null; $selected = array(); $extra = ''; foreach($params as $_key => $_val) { switch($_key) { case 'name': case 'text': case 'value': $$_key = (string)$_val; break; case 'selected': $$_key = array_map('strval', array_values((array)$_val)); break; case 'options': $$_key = (array)$_val; break; default: [...]

0 Comments

smarty类中的insert内建函数的介绍及使用方法

in 程序开发

假定说有一个模板,在页面顶端是一个横幅的位置。横幅可以包含任意的HTML,图形,FLASH的内容,因此我们不可能在这里使用一个静态的连 接,我们也不希望该内容和页面一样被缓存。这里就用得到{insert}标记:模板需要知道#banner_location_id# 和#site_id#值(从配置文件中得 到),并需要调用一个函数来得到横幅的内容。

0 Comments

Smarty中的Insert方法的使用教程

in 程序开发

Smarty中的Insert方法主要用在一些实时更新的地方,如广告位,天气预告,股市动态等类的信息中.
inset.php
内容如下
require_on
ce 'libs/smarty.class.php';
require_once 'msmarty.class.php';

$tpl = new msmarty('./tpl_c');
$tpl->setTpl('./tpl_t');
/**
* showmenu
* 测试smarty插件insert功能
*/
function smarty_insert_showmenu()
{
$banner = '';
return $banner;
}

$tpl->display('test1.html');
?

/test1.html

0 Comments

smarty局部缓存

in 程序开发

Smarty提供了强大的缓存功能。但有时我们并不希望整篇文档都被缓存,而是有选择的缓存某一部分内容或某一部分内容不被缓存。例如你在页面上端使用一个带有广告条位置的模板,广告条可以包含任何HTML、图象、FLASH等混合信息. 因此这里不能使用一个静态的链接,同时我们也不希望该广告条被缓存. 这就需要在 insert 函数指定,同时需要一个函数取广告条的内容信息。smarty也提供了这种缓存控制能力。

我们可以使用$smarty->register_block($params,&$smarty)使整篇页面中的某一块不被缓存。

0 Comments

动态网页制作技巧PHP:详细彻底学习Smarty

in js框架

{$smarty.now}变量用于访问当前时间戳.
可以用 date_format调节器格式化输出. 例如{$smarty.nowdate_format:"%Y-%m-%d %H:%M:%S"}

{$smarty.const}
你可以直接访问PHP常量. 例如{$smarty.const._MY_CONST_VAL}

{$smarty.capture}
可以通过 {capture}..{/capture}结构 截取的输出可以使用{$smarty} 变量访问.

{$smarty.config}
{$smarty}变量 可以访问已经加载的config变量.
例如 {$smarty.config.foo}就可以表示 {#foo#}.

0 Comments