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

Instantiate parser on external page

Discussion in 'XenForo Development Discussions' started by fishb6nes, Jan 22, 2016.

  1. fishb6nes

    fishb6nes Member

    I'm attempting to instantiate a XenForo parser on an external page using the following code as suggested in this thread.
    $parser = XenForo_BbCode_Parser::create(XenForo_BbCode_Formatter_Base::create('XenForo_BbCode_Formatter_BbCode_AutoLink', false));
    // To then parse the $message retrieved from the database as follow
    $message = $parser->render($message);
    However it just prints out 'No access'. Am I missing something?
  2. Chris D

    Chris D XenForo Developer Staff Member

    You need to instantiate XF including the XF autoloader. If the autoloader hasn't been instantiated you will hit this.

    Typically the best way to do what you're trying to do is:


    $fileDir dirname(__FILE__);

    $fileDir '/library/XenForo/Autoloader.php');
    XenForo_Autoloader::getInstance()->setupAutoloader($fileDir '/library');

    XenForo_Application::initialize($fileDir '/library'$fileDir);

    $dependencies = new XenForo_Dependencies_Public();

    $formatter XenForo_BbCode_Formatter_Base::create('XenForo_BbCode_Formatter_BbCode_AutoLink'false);
    $parser XenForo_BbCode_Parser::create($formatter);

    // To then parse the $message retrieved from the database as follow

    $message $parser->render($message);
    fishb6nes likes this.
  3. fishb6nes

    fishb6nes Member

    Thank you Chris, works like a charm.

    Instantiating a 'XenForo_BbCode_Formatter_BbCode_AutoLink' formatter didn't seem to do anything for me, but a 'XenForo_BbCode_Formatter_Base' formatter turns out to do everything I'm looking for.

Share This Page