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

I would like to create a BB Code called "Hide"

Discussion in 'XenForo Development Discussions' started by AndyB, Aug 31, 2014.

  1. AndyB

    AndyB Well-Known Member

    Hello,

    I would like to create a Custom BB Code called "Hide". The purpose of this BB Code is to allow a member to enter into a post some text that will be hidden to all except the author and those with permissions to view this hidden text. For example the member would enter a BB Code like this:

    Code:
    [hide]This text is hidden[/hide]
    
    and only the author of the post and those with the appropriate permissions can view it. For example Moderators and the Administration groups would be able to always see this hidden text contained in the "Hide" BB Code.
     
    Last edited: Aug 31, 2014
  2. AndyB

    AndyB Well-Known Member

    The Custom BB Code page looks like this:

    pic001.jpg
     
    Last edited: Aug 31, 2014
  3. AndyB

    AndyB Well-Known Member

    I have created the following file:

    Andy/Hide/BbCode/Hide.php

    PHP:
    <?php

    class Andy_Hide_BbCode_Hide
    {
        public static function 
    render(array $tag, array $rendererStatesXenForo_BbCode_Formatter_Base $formatter)
        {
            
    $view $formatter->getView();
            if (
    $view)
            {
                
                
    $var 'got here';
                
                
    $template $view->createTemplateObject('andy_hide', array(
                    
    'var' => $var
                
    ));

                return 
    $template->render();
            }    
        }
    }
     
    Last edited: Aug 31, 2014
  4. AndyB

    AndyB Well-Known Member

    At this point the andy_hide template is returned properly. So if I enter the following BB Code into a post:

    Code:
    [hide]This text is hidden[/hide]
    
    The words "got here" is put in place of the BB Code.
     
    Last edited: Aug 31, 2014
  5. AndyB

    AndyB Well-Known Member

    Well I just realized this won't work because if the post is quoted the text will be shown.

    However I this thread will be useful to anyone wondering how to use the PHP Callback in BB Codes.
     

Share This Page