-1

in tpl file for example

{$listings.activation_date} = 2013-12-20 20:46:10

and when use this:

[[$listings.activation_date]]=12.20.2013

how to use :

{assign var=foo value='12.20.2013'}

{if $foo == [[$listings.activation_date]]}

this does not work and throws back this error:

Fatal error! Your request can not be executed!

and another question is how to get today time in tpl file.

Daniel
  • 11
  • 2
  • 6

2 Answers2

3

To get date in tpl file in your php file use this

$smarty->assign('currentDate', $date("Y-m-d"));

in tpl file

<h1>{$currentDate}</h1> //prints <h1>2013-12-21</h1>

And why are you using [[]] brackets in tpl code?

why not use like this

{assign var=foo value='12.20.2013'}
{if $foo == $listings.activation_date}
  • tanx, but i have 2 problem: i don t know where add this code $smarty->assign('currentDate', $date("Y-m-d")); and 2: the brackets is default code for this cms and change 2013-12-20 20:46:10 to 12.20.2013 . i don t know how to get current year with that.:( – Daniel Dec 21 '13 at 01:25
  • smarty have two files to make one page, .php file and .tpl file. i.e home.php and home.tpl you put $smarty->assign('currentDate', $date("Y-m-d")); in home.php and

    {$currentDate}

    in home.tpl. in ur case it might be index.php and to get current year in home.php call date() and use substr method or explode() to get year. and assign that yeat to smarty template variable. all the logic or bussiness logic must be created and handeled in .php file. use .tpl to only make html
    –  Dec 21 '13 at 01:34
  • How can I see the all stuffs pass by smarty php to tpl file like as currentdate? – Daniel Dec 21 '13 at 01:41
  • http://stackoverflow.com/questions/716916/print-all-variables-available-in-a-smarty-template –  Dec 21 '13 at 01:47
0

I finally found myself

in search_result.php

$tp->assign('currentdate',date('Y-m-d'));

in tpl file :

{assign var=foo value=$listing.activation_date|date_format:"%D"}

    {if $foo==$currentdate|date_format:"%D"}
Daniel
  • 11
  • 2
  • 6