Basic php functions in templates?


#1

Hello. I would appreciate if someone more capable than me could help me with one little thing. I have customized my old piwik instalation quite a bit and now on v 2.0 all of that is gone… and so the slow climbing to rebuild it begins :slight_smile: For instance, in the live widget i was having two different backgrounds colors for actions done in the past 30 minutes, or older. It was eyes-catching and for a small website it`s useful to see instantly what are the “active” visitors doing and bring focus to them.

In lastVisits.tpl i was having this:

style="{if $visitor.serverTimestamp > time()-1800} …

i tried to insert in getLastVisitsStart.twig

style="{% if visitor.serverTimestamp > time() - 1800 %}

but i get the error

“The function “time” does not exist in “@Live/getLastVisitsStart.twig” at line 8”

So, how can i invoke basic php functions, like current time in unix seconds, in order to calculate “last 30 minutes”? It was working before in the old .tpls, i customized many of them with all sorts of php functions… now i assume something is different? And what can I do?


#2

anyone? or, if really the new templates will never be customizable again via php functions (bad decision if one asks me), is there a way to reconvert the database to the old format, so that i can return to piwik 1.12?


#3

http://twig.sensiolabs.org/doc/advanced.html#id2

Or you can assign var in view(controller). Something like this:


$view->time = time();
...
return $view->render();


#4

thank you very much for your response! i was hoping that there was a way to just use those basic php functions like i used to do with old .tpls, not define them myself or registering new functions, because i am not a programmer, not at all :slight_smile:

I am now trying to guess how to assign a variable which seems easier with those 2 lines… assuming that you meant to do this in the controller.php file from within the live plugin folder… so far i have failed miserably in the past 3 hours :slight_smile:


#5

Yes. It must be somewhere in the controller, in method which display the appropriate view.


#6

god bless you, i did it… and i also understood how this works, matching public function name from controller.php with template name, so now i know how to fix all my stuff in future… thank you!