English 中文(简体)
巧妙地更改阵列中的元素
原标题:Smarty change elements in array
  • 时间:2010-10-20 08:35:04
  •  标签:
  • smarty

我的模板文件($data)中有一个数组,如下所示

$data.1.name
$data.1.date
$data.1.place
$data.2.name
$data.2.date
$data.2.place
$data.3.name
$data.3.date
$data.3.place

now I would like to check the entire array and remove an item where the date is older then today. The date check i figured out but i m stuck at removing the item.

所以假设第2项比较老,结果应该是

$data.1.name
$data.1.date
$data.1.place
$data.3.name
$data.3.date
$data.3.place

有人知道我是怎么做的吗?如果有可能的话?

最佳回答
{foreach from=$data item=val}
  {if $val.date >= $smarty.now}
    {$val.name}
    {$val.date}
    {$val.place}
  {/if}
{/foreach}
问题回答

暂无回答




相关问题
Smarty: how to evaluate string as a variable

Variable assigned in my template is {$testVariable_123}, where 123 is auto generated and is also assigned to template as {$autoValue} So in my template I want to get value of above variable. {assign ...

How to add an element To Array

Hmm.. thats realy different problem I fetch $links from db linke this $links = $db->GetAll("SELECT * FROM {$tables[ link ][ name ]} WHERE STATUS = 2 AND CATEGORY_ID = ".$db->qstr($id)." {$...

What are .tpl files? PHP, web design

Someone 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= ...

Smarty Concatenation

Hi I am trying to do concatenation in smarty. Here is an example of how I would like to use the code. The php assigns $smarty->assign( myvar ,array(1,5,6,4)); $smarty->assign( myvar2 ,array( a1 ...

Smarty is very slow sometimes

We use Smarty and time to time it really takes a lot of time for it to render a template. Normally it works fine, but sometimes (like 1 random pageview out of 1 000) it takes about 5 seconds to render ...

Smarty Section Making the selected Link Bold

How can I make the selected link from the List below, bold, that you see you are on Page ex. 3 or 5 With this code, If you click on a Link you don t know on which page you are. The smarty code ...

how to pass embed code in javascript

<a href="" onClick="return select_item(<embed src="player.swf" allowfullscreen="true" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" FlashVars="id=&flv=...

热门标签