1. 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

Discussion in 'XenForo Development Discussions' started by Teapot, Feb 2, 2014.

  1. Teapot

    Teapot Well-Known Member

    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 $rendererStatesXenForo_BbCode_Formatter_Base $formatter)
        {
             
    $somethingSomething->createTemplateObject('type_image', array(
                    
    'content' => $tag['children'][0]
                ));
        }
    }
     
  2. Teapot

    Teapot Well-Known Member

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

    Thanks!
     
  3. Chris D

    Chris D XenForo Developer Staff Member

    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();
            }
     
  4. Teapot

    Teapot Well-Known Member

    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 $rendererStatesXenForo_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:
    [​IMG]
    [​IMG]

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

    Chris D XenForo Developer Staff Member

    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.
     
  6. Teapot

    Teapot Well-Known Member

    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!
     

Share This Page