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

XenForo 1.3 - Access Template from Custom BBCode Callback

Teapot

Well-known member
#1
Running into a minor problem with the new BBCode system. I've got a small class set up to deal with the BBCode, which is fine, but I'm getting stuck at how to render a template within my BBCode and, eventually, pass the options and BBCode content into it as $viewParams - the traditional way, doing something like this, no longer works because $_view is protected:

PHP:
$template = $this->_view->createTemplateObject('bb_code_tag_php', array(
                'content' => $content
            ));
So my question is, how do I make this work? Obviously the $somethingSomething is just there as pseudocode and the code doesn't return anything yet:

PHP:
<?php
class Pokecharms_BBCode_PokemonType
{
    public static function render(array $tag, array $rendererStates, XenForo_BbCode_Formatter_Base $formatter)
    {
         $somethingSomething->createTemplateObject('type_image', array(
                'content' => $tag['children'][0]
            ));
    }
}
 

Teapot

Well-known member
#2
Quick bump with permission - now XF 1.3 has been in beta for a while, has anyone figured something like this out yet?

Thanks!
 

Chris D

XenForo developer
Staff member
#3
It's not at all dissimilar from the "traditional" way. There's a public function in the formatter that gets the view:
PHP:
        $view = $formatter->getView();
        if ($view)
        {
            $template = $view->createTemplateObject('type_image', array(
                'content' => $tag['children'][0]
            ));

            return $template->render();
        }
 

Teapot

Well-known member
#4
Thanks a bunch! That was the piece I was missing :) Getting a really bizarre problem now...

When I use that code and try to render a BBCode: I get the following error:

Code:
Call to undefined method XenForo_BbCode_Formatter_ImageCount::getView() in /Volumes/Content/Web/xf/library/Pokecharms/BBCode/PokemonType.php on line 6
My full code is:
PHP:
<?php
class Pokecharms_BBCode_PokemonType
{
    public static function render(array $tag, array $rendererStates, XenForo_BbCode_Formatter_Base $formatter)
    {
        $view = $formatter->getView();
        if ($view)
        {
            $template = $view->createTemplateObject('type_image', array('content' => $tag['children'][0]));

            return $template->render();
        }
    }
}
The settings are as follows:



This is a bizarre problem, I can't find out why XenForo is picking up the wrong renderer.
 

Chris D

XenForo developer
Staff member
#5
That all looks correct. My immediate thought is if you have an old code event listener related to bb code, or some other add-on now interfering with it.

Assuming that there is no other code behind this bb code other than the custom bb code callback and a template you might even be able to just do $config['enableListeners'] = false; in config.php just to immediately discount any other code causing a problem.
 

Teapot

Well-known member
#6
That all looks correct. My immediate thought is if you have an old code event listener related to bb code, or some other add-on now interfering with it.

Assuming that there is no other code behind this bb code other than the custom bb code callback and a template you might even be able to just do $config['enableListeners'] = false; in config.php just to immediately discount any other code causing a problem.
Looks like it was a bug in XF 1.3 Beta 1; upgrading to Beta 2 mysteriously fixed it. :)

Thanks a bunch for all your help!