Is there a way to use a method call of an object as the target of a conditional in a Smarty template?
As a concrete example, I have an object $user
with a method loggedIn()
. I want to use this method to show extra info if the user is logged in.
I can assign the return value of this method to a temporary variable and use this as the target of {if}
:
{user->loggedIn assign="loggedIn"}
{if $loggedIn}
// show extra info
{/if}
Is there a way to skip this intermediate step? I'd like something like this (doesn't work):
{if user->loggedIn}
// show extra info
{/if}
I can't find any examples of using objects like this in Smarty's documentation.
Use assign_by_ref
instead of register_object
:
$smarty->assign_by_ref('user', $user);
Then you can access methods:
{if $user->loggedIn()}
// show extra info
{/if}