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.
Options

Making GDN::Session() available to templates?

codegruntcodegrunt New
edited February 2011 in Vanilla 2.0 - 2.8
Howdy. As far as I can tell, Vanilla does not make the global session object available to Smarty templates. Unfortunately this means that it is often impossible to emulate the functionality of the inline PHP scripts with ".tpl" based Smarty templates.

For example, when displaying comments a class descriptor "Mine" is included based on whether the comment was made by the logged in user. Unfortunately, the $User object setup in Smarty is missing important data such as UserID which makes it impossible to test against. This also leads to issues when trying to generate URLs that require the user ID.

What I have done for now is to create a custom Smarty function that sets the GDN::Session() result as a variable:

library/vendors/SmartyPlugins/function.user_session.php

function smarty_function_user_session($Params, &$Smarty) { if(Gdn::Session()->IsValid()) $Smarty->assign('User_Session',Gdn::Session()); }

This seems to work OK but I was curious if there is a built in way to do this that I am unaware of? Are there any problems with calling this function in a template?

Cheers
Sign In or Register to comment.