Accessing thread/node variables in a helper

bill78

Member
Hello :)

I am using a helper to vary some code that's showing adverts. Within my helper I have access to visitor info with :
PHP:
$visitor = XenForo_Visitor::getInstance();

How is it possible to obtain information about the thread being viewed when the help is called from the thread view or node view pages?

At the moment I'm passing it back from the template, but I was wondering as the ControllerPublic/Thread has already done the business whether there was a way to access in the data directly.

Hope that makes sense!
 
In the thread view you can dump $thread to see what's available.
Code:
{xen:helper dump, $thread}

The same principle applies to other templates.
 
Cheer Brogan, I mean is it possible to access this variable within a helper script rather than through a template and passing it back?
 
It's not really clear what you are trying to do.

Can you post some example code or a code flow?
 
Sorry!

It's possibly a terrible way of doing things, I'm not sure, but I have a template mod for ad_below_top_breadcrumb that inserts this helper:

Code:
{xen:helper example_advert_top,{$contentTemplate},{$forum.node_id}}

Then my helper function is here:
PHP:
public static function advertTop($contentTemplate,$nodeID)
    {
        //Check to see if initialised
        if (self::$isGuest === null) self::_initialise();
      
      
        if (self::$isGuest===false)
        {
                //user is logged in
            return self::adsenseTop(true);
        }
        else
        {
            return self::adsenseTop(false);
        }
          
    }

I was wondering whether things like node ID and thread ID were accessible directly without having to pass them back from the template?

The function of what is displayed is quite simplistic at the moment, but that's what I'm looking to build on.

Thanks in advance :)
 
Top Bottom