So im trying to assign a object to smarty.
$a = FrameworkCore::getUserSessionObj(); // returns the object ofc
$smarty->registerObject('global_session',$a);
{if $global_session->isLoggedIn eq true}
LOGGED IN
{else}
NO
{/if}
Now im trying to put the method call into if statement, but it won't work. Tried it multiple time with different values and other methods.
The output of the method call works fine (see below).
{global_session->getType}
{global_session->isLoggedIn}
So it seems the/my failure is in the if statement, but i can't get it working.
When you use registerObject()
you will add them like custom functions. So you can use expressions like {global_session->getType}
or {global_session->isLoggedIn}
like you did. But you can't use it like variables as in {$global_session}
because you haven't assigned such a variable with assign()
. This also means you can't write code like:
{if global_session->isLoggedIn eq true}
...
{/if}
Check the manual of objects in smarty:
One way is to register objects to the template, then use access them via syntax similar to custom functions.
The other way is to
assign()
objects to the templates and access them much like any other assigned variable.
So when you want to use the object as a variable use assign()
.