XF 2.2 Parse BBCode in custom content type

Sysnative

Well-known member
Hi all,

I've currently got a data table with a custom content type, and I'd like to use the XF BBCode parsing functions to do two things:
  1. Parse BBCode currently stored in the database with this content type, and display this as the correct HTML.
  2. Convert existing raw URLs stored in the database into BBCode URLs.

I believe for the first one, I need to tell the templater to parse the BBCode for specific fields, and return the correct HTML to the end template. I have an idea of the structure of this, but I'm not sure how exactly to go about this / what needs to be done. My actionIndex() controller function is below:


PHP:
public function actionIndex(ParameterBag $params)
    {
        if(!\XF::visitor()->hasPermission('sys_note', 'canView'))
        {
            return $this->noPermission("You do not have permission to view this page.");
        }

        $noteFinder = $this->finder('Sysnative\Test:Note')
            ->where('approval', '=', true)
            ->order('title','asc');

        $page = $params->page;
        $perPage = 50;

        $noteFinder->limitByPage($page, $perPage);

        $viewParams = [
            'notes' => $noteFinder->fetch(),
            'page' => $page,
            'perPage' => $perPage,
            'total' => $noteFinder->total()
        ];

        return $this->view('Sysnative\Test:Note\Index',
            'sysnative_test_note_index', $viewParams);
    }

A "note" entity includes a "description" field that should accept BBCode. What I'm not sure how to do is tell the templater to parse the BBCode in this field.

For the second task, converting raw URLs that are saved in the "description" field into HTML links, I'm not sure where to start with this one - so any advice is appreciated!
 
Top Bottom