1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Accessing thread/node variables in a helper

Discussion in 'XenForo Development Discussions' started by bill78, Jul 7, 2015.

  1. bill78

    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 :
    $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!
  2. Brogan

    Brogan XenForo Moderator Staff Member

    In the thread view you can dump $thread to see what's available.
    {xen:helper dump, $thread}
    The same principle applies to other templates.
  3. bill78

    bill78 Member

    Cheer Brogan, I mean is it possible to access this variable within a helper script rather than through a template and passing it back?
  4. Brogan

    Brogan XenForo Moderator Staff Member

    It's not really clear what you are trying to do.

    Can you post some example code or a code flow?
  5. bill78

    bill78 Member


    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:

    {xen:helper example_advert_top,{$contentTemplate},{$forum.node_id}}
    Then my helper function is here:
    public static function advertTop($contentTemplate,$nodeID)
    //Check to see if initialised
    if (self::$isGuest === nullself::_initialise();
            if (
    //user is logged in
    return self::adsenseTop(true);
    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 :)
  6. Brogan

    Brogan XenForo Moderator Staff Member

    In that case you may be able to pass the variables to the PAGE_CONTAINER template, dpending on what you want to use.

    See the explanation here: Conditional Statements

Share This Page