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

BbCode View

Discussion in 'XenForo Development Discussions' started by Daniel Hood, Jul 30, 2013.

  1. Daniel Hood

    Daniel Hood Well-Known Member

    How do I include a view in my bbcode call so that the templates get preloaded and everything?

    Currently in my model for getting posts I have
    But quotes for example aren't rendering. I'm under the impressions it'll be something like

    But that doesn't work and I can't tell how far off I am.
  2. Chris D

    Chris D XenForo Developer Staff Member

    You shouldn't really be calling the BB Code parser in a model.

    I presume you've got a controller that is ultimately calling something like:

        public function actionTest()
    $postModel XenForo_Model::create('XenForo_Model_Posts');

    $viewParams = array(
    'posts' => $postModel->getPosts()

    "YourAddOn_ViewPublic_Posts" is a view class that can usually either exist or not. Most of the time we don't need to do anything in the view. But if you're doing something with BB Code then doing it in a view class is the most appropriate.

    So you now need:


    class YourAddOn_ViewPublic_Posts extends XenForo_ViewPublic_Base
        public function 
    $bbCodeParser XenForo_BbCode_Parser::create(XenForo_BbCode_Formatter_Base::create('Base', array('view' => $this)));

    XenForo_ViewPublic_Helper_Message::bbCodeWrapMessages($this->_params['posts'], $bbCodeParser);
    Does that make sense?

    The parsed BB code is then available in your template using:

    <xen:foreach loop="$posts" value="$post">
        {xen:raw $post.messageHtml}
    Myke623 and Daniel Hood like this.
  3. Daniel Hood

    Daniel Hood Well-Known Member

    That does make sense, thank you.
  4. Jeremy

    Jeremy Well-Known Member

    You are also calling XenForo_BbCode_Formatter_Base::create one too many times.

Share This Page