smarty

Smarty缓存机制 $smarty->display(

浪尽此生 提交于 2019-12-08 16:31:13
Smarty缓存机制 大家应该知道缓存机制能有效的减轻网站的服务器压力,Smarty模板引擎的一大亮点就是为我们提供了非常简单的缓存操作,下面就让我们学习一下。   首先我们要知道Smarty缓存机制分为全局缓存,部分缓存,局部缓存三种,我们一一介绍。   1、全局缓存   顾名思义,全局缓存就是为整个网站的全部页面都生成缓存页面。 首先我们要操作smarty的配置文件,开启缓存,指定缓存文件目录,并设置缓存的存活时间   $smarty->cache_dir = './cache/'; //设置存放缓存文件的文件夹 $smarty->caching = 1; //开启缓存 0、FALSE代表关闭|非0数字、TRUE代表开启 $smarty->cache_lifetime = 3600; //单位为秒(如果填写-1为永不过期)   接下来我们要去具体的php页面设置与之对应的具体缓存文件的名字   $url=md5($_SERVER['REQUEST_URI']); //将当前页面的URL(包含?后面的所有参数)进行md5加密 $smarty->display('list2.html',$url); //设置缓存文件名   需要注意的是:   $smarty->display('与之对应的模板文件名','缓存文件名的补充部分') 这个方法。   第二个参数不是必须的,如果不写的话

Smarty prints a WHITE SPACE between variables (in Loop)?

不羁的心 提交于 2019-12-08 12:45:56
问题 Assigning from PHP: $smarty->assign("myArrays", Array( Array( "title" => "ABC", "whatever" => 45), Array( "title" => "DEF", "whatever" => 78) )); In Smarty (v3.1.16) .tpl file: {assign "seperator" "|"} {foreach from=$myArrays item=currentItem} {$seperator}{$currentItem.title}{$seperator} {/foreach} Then it will output as: |ABC| |DEF| .. WITH A "SPACE" in-between . And i think it is only in such LOOPS. Why is so? And how to solve it please? 回答1: Use no spaces in the loop: {foreach from=

Regular Expression to match {if cond}foo{else}bar{/if}

白昼怎懂夜的黑 提交于 2019-12-08 11:26:24
问题 I'm having difficulty throwing away the bits of the expression I don't want, and keeping the bits I do. The problem is - given the input string: {if cond}foo{else}bar{/if} I'd like just to have: 0: {if cond}foo{else}bar{/if} 1: cond 2: foo 3: bar And for the input string: {if cond}foo{/if} I'd like just to have: 0: {if cond}foo{else}bar{/if} 1: cond 2: foo 3: The regex I've got at present looks like this: \{if ([a-z0-9]+)\}([^\{]*?)(((?:\{else\})?)(.*?)?)\{/if\} I get the following data back:

How to display selected item at drop down list?

橙三吉。 提交于 2019-12-08 10:42:53
问题 I am currently working on a edit form with drop down list. I have a edit form that display current item from database. But I have no idea how my drop down menu to display current value from database that match drop down list. I know my explanation a bit confuse therefore I picture below will show better explanation. This is one of my edit form that showing drop down menu. What I want is display database value with this view of drop down menu. Example : My database value is Pending . Then it

A voting system with jQuery, PHP and Smarty

青春壹個敷衍的年華 提交于 2019-12-08 09:31:26
I have made a voting feature to my website using only PHP and Smarty. This's the HTML part of it: <p>{$vote} <a href="vote.php?q_vote=vote_up&question_id={$qid}"><i class="icon-thumbs-up"></i></a> <a href="vote.php?q_vote=vote_down&question_id={$qid}"><i class="icon-thumbs-down"></i></a></p> The PHP part of the code takes the vote and refreshes the same page. I want to do the same thing using jQuery so that it won't need to refresh the page. Here is what I wrote in the HTML : $("#q_upvote").click(function() { var vote = "vote_up"; var votedata = ""; votedata = "vote= " + vote; $.ajax({ type:

$_SESSION based language selection is not working properly

删除回忆录丶 提交于 2019-12-08 09:31:24
问题 My website has two languages: English and Russian. These languages' database names are EN and RU. I use an old php+smarty script. This script's default language selection codes like this: if(!isset($_SESSION)){ define('LANGUAGE_ID', 'EN'); } else if ($_SESSION['language'] == '') { define('LANGUAGE_ID', 'EN'); } When I want to see a page in Russian, I visit any page with language phrase (?language=RU) like this: http://www.example.com/index.php?language=RU But these pages doesn't load in

Load smarty tpl with jquery

喜欢而已 提交于 2019-12-08 08:39:04
问题 i would like to load a smarty tpl partial inside a div with jquery, i got: js: function load_new_partial() { jQuery("#ajax_zone").fadeIn('slow').load('/views/partials/partil.tpl'); } inside tpl caller: <a href="#" onclick="load_new_partial();">{$language_array.lang_new_campaign}</a> <div id="ajax_zone">initial div yadadada</div> called tpl: {$user_name_smarty}{$account_array} I have no problem displaying partial.tpl on clicked, problem is that loaded partial.tpl doesn't seem to get any of the

Assigning defaults for Smarty using Object Oriented style

大兔子大兔子 提交于 2019-12-08 08:37:13
问题 I'm just very slowly starting to sink into object-oriented programming, so please be gentle on me. I have a custom class for Smarty that was partially borrowed. This is how the only example reflects the basic idea of using it across my current project: class Template { function Template() { global $Smarty; if (!isset($Smarty)) { $Smarty = new Smarty; } } public static function display($filename) { global $Smarty; if (!isset($Smarty)) { Template::create(); } $Smarty->display($filename); } Then

jsmart - Can't get template contents (in time?)

流过昼夜 提交于 2019-12-08 07:31:07
问题 I'm trying to use jsmart to render Smarty3 templates on the client-side. If you've no experience with them, keep reading because it could just be a simple JavaScript error that I'm making. It works for simple templates: I create the template (which I receive via AJAX), then render it (passing it the data), as per the documentation: var template = new jSmart(templateReceivedViaAJAX); var content = template.fetch({"firstname":"adam", "secondname":"lynch"}); Then I simply stick the rendered

How to Minify Google AdSense JS?

ⅰ亾dé卋堺 提交于 2019-12-08 07:26:42
问题 Whenever I minify the AdSense script I got from Google, it stops working. Any ideas why? Original Code: <script type="text/javascript"><!-- google_ad_client = "xxx"; /* Ad 1 */ google_ad_slot = "2668798369"; google_ad_width = 160; google_ad_height = 600; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> Minified Code: <script type="text/javascript"><!--google_ad_client = "xxx";/* Ad 1 */google_ad_slot = "2338787596";google_ad_width =