smarty2

Get first Smarty Array-Element

℡╲_俬逩灬. 提交于 2019-12-22 08:12:30
问题 How can i get the first smarty array element ? Actually i know how to do this... but i have following issue. I get a array passed that looks like this [DATA] => Array ( [12] => Array ( [content] => foobar ) [1] => Array ( [content] => ) [2] => Array ( [content] => ) [3] => Array ( [content] => ) //this is a snipit of {$myVar|@print_r} this goes down until [11] For some reason there is no [0] and a [12] at this position. I don't know if this will allways be 12 but I know it allways be at the

Generate distinct smarty random numbers

。_饼干妹妹 提交于 2019-12-13 02:19:42
问题 I'm using smarty v2.6 and I want to generate random distinct numbers. I'm looking for an efficient, fast way to do it using already provided Smarty functions. This is my code for generating 5 random numbers (but not distinct): {assign var=min value=1}{assign var=max value =5} {section name=val start=$min loop=$max+1} {assign var=random value=1|mt_rand:15} {$random} {/section} 回答1: if you really need to do it in smarty templates method 1 {assign var="distinct_numbers" value=array_fill(1,15,'x'

Get first Smarty Array-Element

丶灬走出姿态 提交于 2019-12-05 17:29:42
How can i get the first smarty array element ? Actually i know how to do this... but i have following issue. I get a array passed that looks like this [DATA] => Array ( [12] => Array ( [content] => foobar ) [1] => Array ( [content] => ) [2] => Array ( [content] => ) [3] => Array ( [content] => ) //this is a snipit of {$myVar|@print_r} this goes down until [11] For some reason there is no [0] and a [12] at this position. I don't know if this will allways be 12 but I know it allways be at the first position. I can't sort this array because there is another array that has the same sortorder and I

Smarty getting substring of a var with strpos as start and strlen as end

二次信任 提交于 2019-12-04 00:45:55
问题 I am having issue formatting variables in smarty. I was wondering what is the best way to do it. Basically i have a string "ABC | DEFGH" i want smarty to get the substring of "DEFGH" How would i go about doing this? {$var|substr:strpos:"|":strlen} doesn't work 回答1: Just solved this without setting var back in PHP, and by using the built-in function wrappers. Assuming that: $var = "ABC|DEFGH"; {assign var="bar_at" value=$var|strpos:"|"} <li>{$var}</li> <li>{$var|substr:0:$bar_at}</li> <li>{

Smarty getting substring of a var with strpos as start and strlen as end

非 Y 不嫁゛ 提交于 2019-12-01 03:31:18
I am having issue formatting variables in smarty. I was wondering what is the best way to do it. Basically i have a string "ABC | DEFGH" i want smarty to get the substring of "DEFGH" How would i go about doing this? {$var|substr:strpos:"|":strlen} doesn't work Just solved this without setting var back in PHP, and by using the built-in function wrappers. Assuming that: $var = "ABC|DEFGH"; {assign var="bar_at" value=$var|strpos:"|"} <li>{$var}</li> <li>{$var|substr:0:$bar_at}</li> <li>{$var|substr:$bar_at+1}</li> This will print: ABC|DEFGH ABC DEFGH Some info about Smarty 3 in case if someone