XF 2.3 What is the function to convert bb to html?

kenji4861

Member
TLDR : Looking for a function that will convert BB code to HTML


I want to display a post on a custom page.

I first do a mysql query to get the post message
select message from xf_post where post_id=123456

Once I get the 'message', it's in bb format.

Is there a XF function that can easily change this to HTML?

Vbulletin had a bb2html type function.

Skimming through the developers document but I'm not finding it.

Thank you.
 
There may be another way, but I use this code, in my template, with one of my add-ons:

Code:
{{ bb_code({$message}, null, null) }}

I believe it's supposed to be something like this, technically:

Code:
{{ bb_code({$entity.message}, 'content_type', {$entity}) }}
 
Hey thanks mjda, this will work within the xenforo acp templates, but I'm just working with external php files.

Maybe I'm missing how all this works.
 
Ok, so I'm honestly not sure how you'd call \XF::app() from an external PHP script, because everything I do is from within the XF environment, but if you could figure that out, something like this should work:

PHP:
$app = \XF::app();

$renderedMessage = $app->bbCode()->render($message, 'html', '', null, []);

Or, better yet, I'd probably just figure out how to do what you're wanting to do using the XF platform.

I started with the following page a few years ago and have just continued trying to learn from there:

 
@mjda You are a lifesaver! That's exactly what I needed!

This worked!

Code:
require ($DIR . '/forums/src/XF.php');
\XF::start($DIR . '/forums');
$app = \XF::setupApp('XF\Pub\App');
$app->start();
$message = "[b]bold test[/b] - not bold text";
$renderedMessage = $app->bbCode()->render($message, 'html', '', null, []);

Thank you 🙇‍♂️

and thank you for the documentation page too.
 
Back
Top Bottom