smarty

Smarty - 'unable to write file… templates_c'. (smarty_internal_write_file.php:44) [closed]

匿名 (未验证) 提交于 2019-12-03 08:48:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm using Smarty for the first time. It works fine on my laptop (MAMP) but when I try and run a basic template on my production server (Windows) I get this error message: Fatal error: Uncaught exception 'SmartyException' with message 'unable to write file C:\Inetpub\vhosts\path\to\web\root\smarty\templates_c\wrt516e53290e2095.47946913' in C:\Inetpub\vhosts\path\to\web\root\smarty\libs\sysplugins\smarty_internal_write_file.php:44 Stack trace: #0 C:\Inetpub\vhosts\path\to\web\root\smarty\libs\sysplugins\smarty_internal_template.php(201):

Smarty local variable concatenation with string

蹲街弑〆低调 提交于 2019-12-03 08:17:01
问题 How to assign a local template variable with a string concatenated just like below: {$yes_src=const1.'yes'.const2} to be used below in the code in the manner {$yes_src} . 回答1: The way you are doing it is call the "short form" of assign , you just need to use the correct quoting mechanism: {$yes_src="`$const1`yes`$const2`"} Use assign : {assign var="yes_src" val="`$const1`yes`$const2`"} Use cat : {$const1|cat:"yes"}{$const2} You can also simply put the variables next to one another without

Smarty PHP clashing with AngularJS

一曲冷凌霜 提交于 2019-12-03 07:25:18
How do I stop Smarty throwing an error when I'm using AngularJS in the same template. I have a Smarty page template with this code: <li ng-repeat="i in items"> <p class="item">{{i}}</p> </li> And I'm getting a blank page when I view in a browser. I get a big error in my apache error_log, which contains the following: PHP Fatal error: Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template ... <p>{{i}}</p>; unknown tag "i If I swap {{i}} for {{4}} or any other digit it works fine. And I can use maths as well, {{8+2}} will show 10 in the page. Is that the Smarty doing

Zend Framework整合Smarty

自闭症网瘾萝莉.ら 提交于 2019-12-03 06:48:25
基于上一篇所讲的多模块结构进行。 1.下载Smarty,然后复制到library目录下 2.通过插件来控制Smarty模板所在目录,具体的结构如下: 整合Smarty时自定义插件目录结构 3. 通过插件来控制目录 App->controller->plugin->smarty.php : 1 class App_Controller_Plugin_Smarty extends Zend_Controller_Plugin_Abstract 2 { 3 public function preDispatch(Zend_Controller_Request_Abstract $request ) 4 { 5 $module = $request ->module; //得到当前模块 6 $view = Zend_Registry::get( 'smarty' ); 7 $view ->setBasePath(APPLICATION_PATH. '/modules/' . $module ); //指定当前模块目录 8 } 9 } App->View->Smarty.php : 01 class App_View_Smarty extends Smarty 02 { 03 public function __construct( $extraParams = array ()) 04

Smarty - foreach loop 10 times and stop

北城余情 提交于 2019-12-03 06:32:41
Im using the following Smarty code: {foreach from=$entries key=i item=topic} {if $topic.topic_style == question} <li> <a href="topic.php?id={$topic.id}">{$topic.title}</a> </li> {/if} {/foreach} How can i do the {foreach} a maximum of 10 times and then stop? hsz You can use index and break function: {foreach from=$entries key=i item=topic name=foo} {if $smarty.foreach.foo.index == 10} {break} {/if} {if $topic.topic_style == question} <li> <a href="topic.php?id={$topic.id}">{$topic.title}</a> </li> {/if} {/foreach} Break function is described here: Break in Smarty's / Dwoo's foreach You could

Concatenation in smarty

空扰寡人 提交于 2019-12-03 05:53:56
I want to assign the value obtained from the concatenation of these two variables with a string. {assign var="url" value="{$WS_PATH}aircraft_images/{$images[i].image}"} Please let me know how can we do this in smarty. One of these should work: {assign var="url" value=$WS_PATH|cat:"aircraft_images/"|cat:$images[i].image} Or {assign var="url" value="`$WS_PATH`aircraft_images/`$images[i].image`"} I am not sure if the $images[i].image will be parsed correctly, you may have to {assign} it to another variable first You've used assign properly. A simplified example could look like this: yourphpfile

Accessing a variable (local or global) of PHP file from smarty

匿名 (未验证) 提交于 2019-12-03 03:03:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a php file that has some local and global variables (e.g. $foo) an smarty object is called from this file. How can I access $foo from smarty script without changing PHP file? Thanks 回答1: You can't. You have to assign it to smarty within the PHP file. $smarty->assign('foo', $foo); 回答2: If you have a constant variable called BASE, and defined like this: define('BASE', 'Boise'); you can access the variable in smarty the following way: $smarty.const.BASE 回答3: You used to be able to get around this by using {php}{/php} tags, but since this

Why should I use templating system in PHP?

匿名 (未验证) 提交于 2019-12-03 01:54:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Why should I use templating system in PHP? The reasoning behind my question is: PHP itself is feature rich templating system, why should I install another template engine? The only two pros I found so far are: A bit cleaner syntax (sometimes) Template engine is not usually powerful enough to implement business logic so it forces you to separate concerns. Templating with PHP can lure you to walk around the templating principles and start writing code soup again. ... and both are quite negligible when compared to cons. Small example: PHP =

How do I check to see if a Smarty variable is already assigned?

匿名 (未验证) 提交于 2019-12-03 01:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: How do I check to see if a particular value has already been assigned to Smarty and if not assign a (default) value? Answer: if ( $this -> cismarty -> get_template_vars ( 'test' ) === null ) { $this -> cismarty -> assign ( 'test' , 'Default value' ); } 回答1: Smarty 2 if ( $smarty -> get_template_vars ( 'foo' ) === null ) { $smarty -> assign ( 'foo' , 'some value' ); } Smarty 3 if ( $smarty -> getTemplateVars ( 'foo' ) === null ) { $smarty -> assign ( 'foo' , 'some value' ); } Note that for Smarty 3 , you will have to use $smarty-

Strict Standards: Non-static method STemplate::assign() should not be called statically

匿名 (未验证) 提交于 2019-12-03 00:59:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: i Upgrade my old xampp (1.7.3) localhost server to 1.8.0 . now, not work smarty template engine (2.6.6) in my all page and i see Strict Standards error. what's problem? how to fix this ? NOTE : This Wroked Fine In Old Xampp(1.7.3). Section of Error : Strict Standards: Non-static method STemplate::assign() should not be called statically in C:\xampp\htdocs\tube\include\config.php on line 88 Strict Standards: Non-static method STemplate::create() should not be called statically in C:\xampp\htdocs\tube\libraries\mysmarty.class.php on line 42