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

XF 1.3 BB Code not working :s

Discussion in 'Styling and Customization Questions' started by MichaelDance, Jun 28, 2014.

  1. MichaelDance

    MichaelDance Well-Known Member

    I'm trying to do a BBCode which only shows to Admins and Moderators but for some reason this BB Code shows to everyone. Confused me.

    xenforobbcode.PNG

    What shows when a user isn't logged in or a non Moderator / Administrator:

    Logout.PNG
    ---
    I've tried following: http://xenforo.com/community/thread...b-code-in-xenforo-a-comprehensive-guide.6320/

    PHP:
    <?php

    class MODRelease_EventListener_MODRelease
    {
        public static function 
    listen($class, array &$extend)
        {
            if (
    $class == 'XenForo_MODRelease_Formatter_Base')
            {
                
    $extend[] = 'MODRelease_MODRelease_Formatter_Base';
            }
        }
    }
    PHP:
    class MODRelease_MODRelease_Formatter_Base extends XFCP_MODRelease_MODRelease_Formatter_Base
    {
        protected 
    $_tags;
        public function 
    getTags()
        {
            
    $this->_tags parent::getTags();
            
    $this->_tags['modreserve'] = array(
                
    'hasOption' => false,
                
    'replace' => array('<i style="color:red;"><b>A reserve has been set by the seller.</b></i><br /><xen:if is="{$visitor.is_admin} OR {$visitor.is_moderator}"><p>Reserve Price: <b>''</b></p>')
            );
            return 
    $this->_tags;
        }
    }
    Thank you for your help.
     
    Last edited: Jun 29, 2014
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Template syntax doesn't work there. If you view the source code of the page you will notice that the conditional is present in the source. It shows raw, like this:

    Code:
    <xen:if is="{$visitor.is_admin}">...</xen:if>
    
    The browser doesn't render it but it's there which shows that XenForo doesn't parse template syntax in BB code replacements.

    This is possible with an addon, but that then becomes a development question.
     
    MichaelDance likes this.
  3. MichaelDance

    MichaelDance Well-Known Member

    Oh dam haha was hoping it wouldn't be that. Thank you mate.
     
  4. Chris D

    Chris D XenForo Developer Staff Member

    I saw your other thread, but you might find this quite simple.

    I would recommend using the Custom BB Code system included in XenForo 1.3 and set up a PHP callback for your BB Code. Here's a very simple template of how that could work:

    PHP:
    <?php

    class YourAddOn_BbCode_YourCallback
    {
        public static function 
    tagYourBbCode(array $tag, array $rendererStatesXenForo_BbCode_Formatter_Base $formatter)
        {
            
    $view $formatter->getView();
            if (
    $view)
            {
                
    $viewParams = array();

                
    $template $view->createTemplateObject('your_template_name'$viewParams);
               
                return 
    $template->render();
            }
            else
            {
                return 
    $formatter->renderTagUnparsed($tag$rendererStates);
            }
        }
    }
    The key point to note is that under normal conditions this can return a standard template. In that template you can use the XenForo template syntax as you were attempting to do.
     
    AlexT, MichaelDance and Brogan like this.
  5. MichaelDance

    MichaelDance Well-Known Member

    Thank you mate I tried doing that and I got the tag sort of working it vanishes so I think I need to learn a bit more before I do anything haha.
     

Share This Page