A
A
Alexander Shapoval2017-05-17 23:34:22
Smarty
Alexander Shapoval, 2017-05-17 23:34:22

How to create an object in Smarty?

Greetings, tell me how to create an object in the Smarty template?
Calls the usual function:
{$func = func()}
But the object does not want to be created:
{$object = new object()}
I need to get the questionnaire data in php in the template, it looks like this: How can I write something like this in the Smarty template? I made a small crutch in the form of a static method in the User class that returns this object directly
$ank = new User($id);

static function getObject($id_user){
    return new User($id_user);
}

And in the template prescribed
{$ank = User::getObject($id)}
Is there a more normal way out of the situation?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DevMan, 2017-05-18
@sanek_os9

a more normal way is to get the necessary data in your code / controller and pass it to the template as a regular template variable when it is called.
www.smarty.net/docs/en/language.variables.tpl#lang...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question