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

DiscussionController->_tpl_vars not found

Encountered this problem after changing my template from Smarty to PHP (mentioned in another post, but probably lost in the thread of a separate conversation). The pages all work apart from when I drill down to the post itself, and then this error pops up.

DiscussionController->_tpl_vars not found

Assuming it means a required template variable isn't being passed along properly. Another symptom which tells me this is the case is that my PHP code:

<?php if ($this->_tpl_vars['User']['SignedIn']): ?>
    <?php echo Gdn_Theme::Module('MeModule', array('CssClass' => "hidden-xs"));?>
<?php else: ?>
    <li><a href="<?php echo Url('/'); ?>register" class="">Register</a></li>
    <li><a href="<?php echo Url('/'); ?>signin" class="">Sign In</a></li>
<?php endif; ?>

… always shows the Register / Login links regardless of whether I am logged in or not.

I'm including the necessary head / footer assests, firing the AfterBody event and checking the code, the header and footer assets appear (no source code for the AfterBody event, but no idea whether that's supposed to. I'm calling them within my template in the following way:

<?php $this->RenderAsset('Head'); ?>
<?php $this->RenderAsset('Foot'); ?>
<?php $this->FireEvent('AfterBody'); ?>

Does this seem correct? Where do I need to start digging around for where _tpl_vars are defined?

Cheers.

Comments

  • Options
    hgtonighthgtonight ∞ · New MVP
    edited February 2014

    _tpl_vars is a property of the Smarty class object. Since you aren't using Smarty, you have to use the underlying information. Smarty templates are rendered through the Gdn_Smarty::Render() method. All data available to the Smarty templates is in there.

    You will find something like this:

    // Assign some information about the user.
    $Session = Gdn::Session();
    if($Session->IsValid()) {
      $User = array(
        'Name' => $Session->User->Name,
        'CountNotifications' => (int)GetValue('CountNotifications', $Session->User->CountNotifications, 0),
        'CountUnreadConversations' => (int)GetValue('CountUnreadConversations', $Session->User, 0),
        'SignedIn' => TRUE);
    } else {
      $User = FALSE; /*array(
        'Name' => '',
        'CountNotifications' => 0,
        'SignedIn' => FALSE);*/
    }
    
    $Smarty->assign('User', $User);
    

    So, Smarty: {if $User.SignedIn} translates to PHP: if(Gdn::Session()->IsValid()).

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Options

    Ah, I see. Thanks - that's got it working now.

Sign In or Register to comment.