[Solved] Passing $variable to a template

Adam K M

Active member

I'm awfully new to extending controllers and the subview, and right now, from working with responseView, I was wondering - how do I go about accessing passed variables in my template that's rendered out from the response view?

The current responseView I've got looks like:
        return $this->_getWrapper('XenForo_ViewPublic_Account_Guildarea', 'GuildArea', $this->responseView('GuildArea', 'account_guildarea', $viewParams) );
As you can see, I've got the account_guildarea template, but I don't know how to access the $viewParams from within that template.

Any help is greatly appreciated! :)


Well-known member
I am a bit outdated with xenforo programming. I usually extended library/ControllerPublic/* classes. You can take a look there and see that all you have to do is to extend an existing class and the usual way is to extend the array that is delivered to the View. To keep it short: 1. extend the controller class 2. after the controller class is executed, your script begins 3. you add some value to an existing array that is used within the response view like $viewParams['flower']['color'] = 'green'; 4. $viewParams now contains the original values as well as your value. So in the template you can write something like {xen:raw $flower.color}

Using the View is kind of advanced I guess :D I did modify the View but only when I could not do that within the Controller.

Adam K M

Active member
I actually just figured out how to do it myself, from looking at this thread.

So for future reference to anyone who stumbles across this.. here's an example of passing a variable called $CustomText which contains "My Custom Text" to the view.

        $viewParams = array(
            'CustomText' => 'My Custom Text'
        return $this->_getWrapper('XenForo_ViewPublic_Account_Guildarea', 'GuildArea', $this->responseView('GuildArea', 'YOUR_TEMPLATE', $viewParams) );
And finally, in YOUR_TEMPLATE you can go ahead and use the xenforo variable {$CustomText} and it will render out My Custom Text. Hope that this helps someone!