smarty

Print all variables available in a Smarty template

左心房为你撑大大i 提交于 2019-11-30 08:08:46
How do you print all variables available in the context of a Smarty template? Something like the Django debug trace that lists everything being passed. Thanks Aron Rotteveel Use {debug} From the manual : {debug} dumps the debug console to the page. This works regardless of the debug settings in the php script. Since this gets executed at runtime, this is only able to show the assigned variables; not the templates that are in use. However, you can see all the currently available variables within the scope of a template. $debugging = true must be enabled in your settings or class, and site

How do you increment an assigned variable in smarty without displaying it

只谈情不闲聊 提交于 2019-11-30 06:03:57
So I have an assigned variable in smarty: {assign var=number value=0} Now I can increment it using {$number++} or {++$number} Which is exactly what I need, only problem is, it displays the value of $number on the page. Is there a way I can increment the value but not display it? This is not used inside of a loop otherwise I would use something like iteration or index. You could do this: {assign var=val value=1} {assign var=val value=$val+1} {$val} // displays 2 The above will be compiled to: $this->assign('val', 1); $this->assign('val', $this->_tpl_vars['val']+1); echo $this->_tpl_vars['val'];

Smarty: How to reference to the associative array index

一笑奈何 提交于 2019-11-30 04:58:55
Array $imagelist: Array ( [additional] => Array ( [count] => 2 [image] => Array ( [nokia_e61_1.jpg] => Array ( [name_body] => nokia_e61_1 [name_ext] => jpg ) [nokia_e61_2.jpg] => Array ( [name_body] => nokia_e61_2 [name_ext] => jpg ) [nokia_e61_3.jpg] => Array ( [name_body] => nokia_e61_3 [name_ext] => jpg ) [nokia_e61_4.jpg] => Array ( [name_body] => nokia_e61_4 [name_ext] => jpg ) ) ) [main] => nokia_e61 ) The value nokia_e61_1.jpg is kept in {$getvars.imagename} . I wrote {$imagelist.additional.image.`$getvars.imagename`.name_body} but it doesn't work. Please help. see if {$imagelist

Smarty : substr a variable

允我心安 提交于 2019-11-30 01:13:56
问题 How can I print the first n characters of a smarty variable, e.g. the first 30 characters of {$var}? 回答1: You should use truncate modifier: {$var|truncate:30} More information here. 回答2: Now there is a function: {$var|substr:0:30} or mb_substr for UTF-8 variables: {$var|mb_substr:0:30} 回答3: Regarding to your problem Jojo already gave the correct answer. You should use truncate modifier: {$var|truncate:30} But for usability and seo-reaons it would be better to shorten the text via css with

{if not isset} Smarty

早过忘川 提交于 2019-11-30 01:07:22
问题 what is the code for smarty for if (!isset($var)){ ? if using {if $x eq '5'} when $x is not defined in smarty , it gives an error function call 'get_template_vars' is unknown or deprecated. . this is what i believe so far as i lost hope in trying to know where did this error come from ! Thanky you . 回答1: {if ! isset($var)} body must be at least 30 characters. :) {/if} 回答2: Try this. {if $missing_var|default:FALSE} NOT MISSING {else} MISSING {/if} 回答3: Try This {if $var} Active {else} Inactive

Formatting numbers with thousands separator Smarty PHP

大憨熊 提交于 2019-11-29 23:46:21
Im trying to format numbers with thousands separator Smarty. So for example 1000 becomes 1,000. Thanks. or you can use php function inside smarty, this is for number_format, you can use other php function too :) PHP : number_format($number, 2, '.', ','); SMARTY : {$number|number_format:2:".":","} or just in smarty use {$var|number_format:0} Try to use string_format , it uses sprintf to format your string. 来源: https://stackoverflow.com/questions/3193710/formatting-numbers-with-thousands-separator-smarty-php

How to change PHP Smarty plugin template file extension in NetBeans?

旧街凉风 提交于 2019-11-29 21:15:18
问题 NetBeans uses PHP Smarty Framework plugin for *.tpl files. Is it possible to change this to *.htm? I use .htm extension for smarty templates and would like to benefit from this PHP Smarty plugin. How can I do that? 回答1: In NetBeans (with the PHP Smarty Framework plugin installed): Click on the Tools menu, and select Options Click on Miscellaneous located toward the right side of the top icon bar of the Options dialog. Click on the Files tab. In the File Extension combo-box field, select htm .

smarty 的一些变量访问

一个人想着一个人 提交于 2019-11-29 20:06:31
{$smarty}保留变量不需要从PHP脚本中分配,是可以在模板中直接访问的数组类型变量,通常被用于访问一些特殊的模板变量。例如,直接在模板中访问页面请求变量、获取访问模板时的时间戳、直接访问PHP中的常量、从配置文件中读取变量等。 1.在模板中访问页面请求变量 我 们可以在PHP脚本中,通过超级全局数组$_GET、$_POST、$_REQUEST获取在客户端以不同方法提交给服务器的数据,也可以通 过$_COOKIE或$_SESSION在多个脚本之间跟踪变量,或是通过$_ENV和$_SERVER获取系统环境变量。如果在模板中需要这些数组,可 以调用Smarty对象中的assign()方法分配给模板。但在Smarty模板中,直接就可以通过{$smarty}保留变量访问这些页面请求变量。 在模板中使用的示例如下所示: PHP代码 1. { $smarty .get.page} {* PHP方式: $_GET [ "page" ] *} 2. { $smarty .post.page} {* PHP方式: $_POST [ "page" ] *} 3. { $smarty .cookies.username} {* PHP方式: $_COOKIE [ "username" ] *} 4. { $smarty .session.id} {* PHP方式: $_SESSION [ "id"

PHP “Document Expired” after using the back button

一世执手 提交于 2019-11-29 18:12:48
I have a form where I am filing some informations in a wizard. This page is reaching by POST and displayed with Smarty. Once I filed all the informations in, I am using another post to get to another page. Now, the problem is that when I am trying to go back with the BACK button, I am geting the "Document expired" message. Is than a normal thing while I am using POST or? I am trying right now to use GET but nothing changes, or my GET is written wrong. Here is a small schema: Page 1 -> POST -> Page 2 (wizard) -> POST -> Page 3 When I try to come back from page 3 to page 2, I am geting the doc

how to assign a javascript variable to a smarty variable

别等时光非礼了梦想. 提交于 2019-11-29 18:02:50
I got a problem regarding how to assign a java script variable to a smarty variable. Here is the code snippet. function getDateInfo(date, wantsClassName) { var as_number = Calendar.dateToInt(date); //This as_number is the variable which should be assigned to smarty variable } How can i accomplish this. any help will be appreciated.. Thanks n advance -- Fero You can't assign a client-side value to a smarty variable, as smarty is a templating language that runs on the server. Smarty assignments can only be done on the server-side, that is to say, from PHP. E.g.: $smarty->assign('timestamp',time(