Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Execute php in .tpl or template tag to check if user is signed in
I'm looking to either find a way to include php into my template file or find a way to determine if a user is logged in. I need to display a few links if the user isn't.
I know in Smarty you can usually use {php}{/php} to execute php. It looks like this is disabled somewhere within Vanilla. Is there a way to turn this back on?
If not, is there anyway to determine if a user is logged in from within a template file?
I know in Smarty you can usually use {php}{/php} to execute php. It looks like this is disabled somewhere within Vanilla. Is there a way to turn this back on?
If not, is there anyway to determine if a user is logged in from within a template file?
Tagged:
0
Comments
You should not need to use PHP within your Smarty templates for this. Instead, add a {debug} call at the top of your template and look at what is available to Smarty. Most likely you will have $User (which may or may not have the user ID available). Also, there are a handful of functions exposed to Smarty via its plugin architecture (which is very simple to add too). For example there are these functions available:
{signin_link}
{signout_link}
There is also "block_permission" which uses Gdn::Session()->CheckPermission() that might work for your needs (I have not researched how CheckPermission() works as of yet).
Personally I added a simple plugin to gain access to the session:
function smarty_function_user_session($Params, &$Smarty) { if(Gdn::Session()->IsValid()) $Smarty->assign('User_Session',Gdn::Session()); }
Cheers