XF 2.2 Write HTML code without it being rendered in the browser

Nicolas FR

Well-known member
I'm doing a basic blocks tutorial in XenForo in a page-node.
I would like to be able to type some HTML code without it being rendered in the browser to show how to construct the blocks. Currently I have to type the code in a message body and take a screenshot but it doesn't look really good.

Capture web_17-10-2022_103641_localhost.jpeg

Anyone know how to do it? Thanks !
 
Solution
There may be a simpler solution, but you can use BB codes even in the template of a page node. Example:

{{ bb_code("[CODE=html]<h1>Test</h1>[/CODE]", null, null) }}

Nicolas FR

Well-known member
Great !
Just i have to escape all the " otherwise the template ca't be saved, error on lines...

Code:
<div class=\"block\">
    <div class=\"block-container\">
        <div class=\"block-minorHeader\">
            block-minorHeader
        </div>
        <div class=\"block-row block-row--minor\">
            block-row block-row--minor
        </div>
        <div class=\"block-row block-row--minor\">
            block-row block-row--minor
        </div>
        <div class=\"block-footer\">
            block-footer
        </div>
    </div>
</div>
 

Nicolas FR

Well-known member
I get an error using BB codes in templates.

In the public view the render is ok but in dev mode i get this
  • Template public:_page_node.4: [E_DEPRECATED] explode(): Passing null to parameter #2 ($string) of type string is deprecated (src\XF\SubContainer\BbCode.php:23)

code i wrote in the template

Capture web_23-11-2022_19322_localhost.jpeg

public view

Capture web_23-11-2022_19291_localhost.jpeg

but whatever i put between {{ bb_code("[CODE=html] and [/CODE]", null, null) }} i got the error.
 

Nicolas FR

Well-known member
I solved the error!!
First time in my life that I understood a little something from a post on StackOverflow!

Well I fumbled a bit and maybe got lucky but the error no longer appears with this syntax
{{ bb_code("[CODE=html] ... [/CODE]", '', '') }}

null parameter replaced by ''
 

JRobert

Active member
You can't use the HTML <code></code> tags?

 
Top