Trying to Attain a Variable within a Template

CaptainMorgan

Active member
My Listener contains a function to load the ControllerPublic Index.php I've made. It also contains my templateHook that determines where in the sidebar the admin would like to display this particular block for his users.

In the ControllerPublic_Index, and for testing purposes, I've stripped the code down to this:

Code:
public actionIndex()
{
       $viewParams = array('my_variable' => 'FooGoo<br />',
                           'my_second_variable' => 'Bar<br />');

        return $this->responseView('MyAddon_ViewPublic_Index', 'mytemplate_sidebar_main', $viewParams);
}

My variables are available in the template yet for some reason which I cannot determine, it becomes the ONLY template on the index page. So, in essence, what was originally intended as only a sidebar block, now displays across the whole page.

Any ideas what I might be doing wrong?
Thanks
 
If your extending an existing controller you need to return the parent response + yours. I'm at work and honestly don't remember this off the top of my head. But if you look at pretty much any plugin doing something similar you will see how its done.

Never mind it still sounds like your only returning those variables. I think I missed the fact that it looks like your doing a standalone addon
 
Last edited:
If your extending an existing controller you need to return the parent response + yours. I'm at work and honestly don't remember this off the top of my head. But if you look at pretty much any plugin doing something similar you will see how its done.

Thank you rain.

Either way I extend:

Code:
class My_Directory_Class extends XFXP_My_Directory_Class {}

or

Code:
class My_Directory_Class extends XenForo_ControllerPublic_Abstract {}

Neither seem to resolve the issue. But further, what is the proper way to return the parents *and* my response? I've seen:

Code:
      $response = parent::actionIndex();

        if ($response instanceof XenForo_ControllerResponse_View) { // and then anything in here never gets called because apparently this resolves to false      

                $response->params += array(
                      'my_variable' => $foo_var,
                      'my_second_variable' => $foo_choo_bar);     
        }
        return $response;

Using this approach, nothing is returned... based on the dozens of plugins I've looked at.
Thanks
 
Okay I'm a bit confused. So your listener is to add a block to the sidebar of an existing page right? Or is it a stand alone addon page?

I think you might be checking against the wrong controller. I might be wrong. I guess your trying to target all pages with a sidebar? Have you tried a more narrow scope and just did the forum pages view controller as a test?

If its a stand alone addon you shouldn't need to check the controller I don't think. I don't on my punk buster viewer
 
rain - that is probably correct, at least sounds correct.
Okay I'm a bit confused. So your listener is to add a block to the sidebar of an existing page right?

Indeed.

If I were to narrow the scope, which controller should I target for just the forum's pages?

Thanks!
 
If its a stand alone addon you shouldn't need to check the controller I don't think. I don't on my punk buster viewer

Do you have a link to this viewer? I'd like to check it out for comparison.

So are you saying I can bypass the controller altogether and pass the variables through the listener? How would I do that?
 
Hmm pain in my butt doing this from a phone. Wish someone decent would come help lol.

I sees in addon that adds a sidebar block to our forum page extending this

XenForo_ControllerPublic_Forum

And then basically does its work like this

public function actionIndex()
{
$parent = parent::actionIndex();


));

$parent->params['something'] = $something;

return $parent;
 
I'm just confused. You are saying having your listener extend that controller was overriding the home page? Shouldn't happen.

Anyways the main reason to check in your controller which controller instance its in is to prevent unnecessary running of the code as well as any errors such things might cause. Like in my one and only public addon I have to make sure its a thread view otherwise redirect threads cause errors etc.
 
Top Bottom