smarty

smarty中常用的流程控制逻辑

泄露秘密 提交于 2019-12-05 00:35:01
if else {if $age > 18} <div>年满十八岁!</div> {else if $age > 16} <div>年满十六岁!</div> {/if} {if $age > 18} <div>年满十八岁!</div> {else} <div>未满十八岁!</div> {/if} foreach <!-- $arr 是一个一维数组 --> {foreach $arr as $key => $value} {$value} {/foreach} section <!-- $arr 是一个一维数组 --> {section name=key loop=$arr} {$arr[key]} {/section} 来源: https://www.cnblogs.com/zxcv123/p/11891828.html

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

前提是你 提交于 2019-12-04 23:08:30
问题 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

Create an array in smarty template? [duplicate]

℡╲_俬逩灬. 提交于 2019-12-04 22:28:23
This question already has an answer here: How to assign an array within a smarty template file? 5 answers I need to create a new array from other one dimensional array in smarty template. So, what are the best possibilities to create an array in template file. Thanks, Sachin Smarty3 allows you to {$var = ['foo' => 'bar', 'sub' => [1, 2, 3]]} and {$var.foo = 'other'} if those options don't suffice, write a plugin function . In the past, I have used two approaches - an evil and a dirty one - to quickly assign an array inside a tpl: {* Am I evil? *} {php} $array = array("cat", "dog", "rabbit");

disable smarty notice

杀马特。学长 韩版系。学妹 提交于 2019-12-04 21:34:01
问题 I would like to disable smarty-s notices. This exactly: Notice: Undefined variable: xy Because I know that some variables are undefined and in some cases I don't even want to define them. BUT I don't want to disable other PHP notices. Thanks for help! 回答1: You should use this: http://www.smarty.net/docs/en/variable.error.reporting.tpl Just set $smarty->error_reporting = E_ALL & ~E_NOTICE; 回答2: You should make your checks on the variables and make sure they are defined and set before using.

Aptana smarty support?

北城以北 提交于 2019-12-04 16:24:16
Is there any way to make aptana (2 or 3) support smarty ? Code color, etc.. I read people talking about how they like to have smarty support in Aptana 3 as in Aptana 2, but i don't find it even for Aptana 2! Thank you. I just installed smartypdt http://code.google.com/p/smartypdt/ on Aptana 2. Just go to help > install new software then click on "add" and choose the zip file you just downloaded. Uncheck "group items by category" then check the new smarty package that just appeared and keep clicking next . Make sur the .tpl are not associated with other formats. You can associate .tpl files

Smarty PHP clashing with AngularJS

ε祈祈猫儿з 提交于 2019-12-04 10:40:40
问题 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

Removing emojis from variable

China☆狼群 提交于 2019-12-04 08:44:00
问题 I'm using Smarty to pass in and display the contents of a first_name variable. Some users have Emoji characters (http://en.wikipedia.org/wiki/Emoji) in their first_name and I am wondering how I can either a) conditionally not display a user's first_name if it contains emojis or b) filter out emoji characters from first_name . Can this be done with Smarty? Can it be done with PHP in Smarty? 回答1: The emoji are encoded in the block U+1F300–U+1F5FF. preg_replace('/\xEE[\x80-\xBF][\x80-\xBF]|\xEF[

Shouldn't mysql_real_escape_string() leave slashes in Database?

天大地大妈咪最大 提交于 2019-12-04 04:37:30
问题 Im using smarty and mysql_real_escape_string() for user input, and when I insert some code with ' or " , and lookup in phpmyadmin it shows without backslashes. When I get record from DB i doesn't have backslashes also. But when I just pass escaped string without inserting into the db it is backslashed. Shouldn't it add slashes, insert with them and then I would strip them when i would output? Or am I missing something? 回答1: You're missing it - escaping with backslashes is meant to ensure that

Smarty If URL Contains

可紊 提交于 2019-12-04 02:37:17
Using Smarty Tags I'd like to determine if an URL contains a word, something like: {if $smarty.get.page contains "product.php"} ..... I know contains doesn't exist, but how could I easily go about writing something similar to achieve the above code? You can use strpos to check if a string has another string inside of it. $pos = strpos($smarty.get.page, "product.php"); if($pos !== false) { // found, do something } Except you need to wrap it in {php} and {/php} . $smarty.get.page translates to $_GET['page'] , so you could replace it with the GET variable as well. All PHP conditionals and

Smarty : evaluate a template stored in a PHP variable

☆樱花仙子☆ 提交于 2019-12-04 02:12:45
i have a php variable which has html/smarty code in it $x='<a href="{$link}" >{$title}</a>'; This data is fetched from database , i want to evaluate it using smarty and put the output into a php variable (to print it out or to save it to the database again) . Thanks Edit : i want the content of X to be evaluated using smarty , as if the content of x is stored in a file.tpl then $y=$smarty->fetch('file.tpl'); ... want to do it without the need to save the content of x into a file If you're using Smarty 3, you can easily do it by $smarty->fetch('string:'.$template_string); or 'eval:'.$template