smarty

Is it possible to format a number to 2 decimal places with Smarty PHP

 ̄綄美尐妖づ 提交于 2019-12-18 12:46:16
问题 Is it possible to format a number to 2 decimal places with Smarty PHP? Thanks. 回答1: string_format accepts sprintf formatting options: {$number|string_format:"%.2f"} 回答2: {$number|number_format:2} is what you want 回答3: {$number|round:"2"} also works 回答4: To display 2 instead of 2.00 you can use : replace in Smarty PHP See below example - $number = 2.00 {$number|replace:'.00':''} Output :- 2 Hope this helps. 来源: https://stackoverflow.com/questions/2409110/is-it-possible-to-format-a-number-to-2

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

本小妞迷上赌 提交于 2019-12-18 12:04:58
问题 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. 回答1: You could do this: {assign var=val value=1} {assign var=val value=$val+1} {$val} // displays 2 The above will be compiled

Smarty: How to reference to the associative array index

拟墨画扇 提交于 2019-12-18 11:50:02
问题 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

how to assign a javascript variable to a smarty variable

你离开我真会死。 提交于 2019-12-18 09:45:43
问题 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 回答1: You can't assign a client-side value to a smarty variable, as smarty is a templating language that runs on the server. Smarty

Howto generate json with smarty?

橙三吉。 提交于 2019-12-17 16:16:36
问题 In Smarty, is there a standard function or an easy way to generate json from an array, as json_encode() does in php? Actually It seems there is not in smarty documentation but wanted to ask anyways. Thanks, Sinan. 回答1: This should work. The @ makes smarty run the modifier against the whole array, otherwise it does it for each element. {$myarray|@json_encode} If $escape_html is enabled, you will need to use nofilter : {$myarray|@json_encode nofilter} 回答2: While {$myarray|@json_encode} does in

Using PHP code in Smarty tpl FIle

余生颓废 提交于 2019-12-17 12:48:29
问题 I am new to smarty and I want to use php code in template file i-e tpl file. I have seen the documentation and searched on google but could not find how to use php code they say we need to configure smarty to allow php execution but could not find how to do it. Kindly help me in this regard. Thanks 回答1: Easy as boiling an egg! {php}echo "hello!"{/php} Second link down, for reference. Edit as of Smarty 3.1: As of Smarty 3.1 the {php} tags are only available from SmartyBC. Source: http://www

What is .tpl files? php, web design

不问归期 提交于 2019-12-17 08:54:40
问题 A man wants me to redesign a site run in PHP (VideoCMS). But when I asked him to send me the source he has given me *.tpl files instead of *.php. There is some code inside them: {include file='header.tpl' p="article"} <br /> <table width="886" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="150" valign="top"> <div id="reg_box"> <h3 class="captions">{$lang.articles}</h3> <div id="list_cats"> <ul> {$article_categories} </ul> </div> </div> <br /> <div id="reg_box"> <h3 class=

Why should I use templating system in PHP?

╄→尐↘猪︶ㄣ 提交于 2019-12-17 04:46:06
问题 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

smarty cache and login states

亡梦爱人 提交于 2019-12-14 03:54:22
问题 I was wondering. How do you guys deal with scenario of website where you have login and log out states at the top. So if someone is logged in, you say "Hello Scott". If someone's not logged in, it says "Log In". I am using force compile = false. And using (!$smarty->is_cached('index.tpl',$template_cache_id)) { do something } What do you guys use to keep some sections not cache and others cached for such a common scenario? My site is photoidentify.com Thanks! 回答1: I have defined a block

cannot open pdf file generated using dompdf

你离开我真会死。 提交于 2019-12-14 03:44:30
问题 i am trying to generate a pdf file from smarty template using dompdf:code is below:- require_once('dompdf/dompdf_config.inc.php'); $dompdf = new DOMPDF(); $dompdf->load_html($smarty->fetch(CURRENT_TEMPLATE.'/module/shopping_cart.html')); $dompdf->render(); $dompdf->stream("sample.pdf"); a pdf file is generated,but when i try to open the pdf file a error message is displaying as below "Acrobat cannot open the 'sample.pdf' because it is either not supported file type or because file has been