XF 1.5 How to use BB Code in the template?

MES LAB

Member
Hi, we have some pages with using template. How we can using BBCode to remove the amount of HTML/js in the template?

I've searched the entire internet but all I've found is {xen:helper bbCode, $parser, $htmlContent} but where is the parser? How can I pass a parser for a built-in BB code, let say "B" for bold, or a custom BB code, for example "gallery" for the lightbox, and the params? And is it OK to use a string for $htmlContent?

I've use the following syntax but not work: {xen:helper bbCode, "gallery", "<div>a.jpg</div><div>b.jpg</div><div>c.png</div>"}
 
Hi, we have some pages with using template. How we can using BBCode to remove the amount of HTML/js in the template?

I've searched the entire internet but all I've found is {xen:helper bbCode, $parser, $htmlContent} but where is the parser? How can I pass a parser for a built-in BB code, let say "B" for bold, or a custom BB code, for example "gallery" for the lightbox, and the params? And is it OK to use a string for $htmlContent?

I've use the following syntax but not work: {xen:helper bbCode, "gallery", "<div>a.jpg</div><div>b.jpg</div><div>c.png</div>"}

What are you trying to do exactly? what is the objective that you are trying to reach? and what the hell is this <div>a.jpg</div><div>b.jpg</div><div>c.png</div>!

to specify an image path you should use something like <img src="image/path">
 
I want to reuse the BB code in the template, so I don't need to rewrite all the work in pure HTML!

Let say, the gallery BB code, it process the inside images, wrap them in some lightbox wrapper, and add js, css to HTML <head> on the fly.

Normally, when using in the post, it should be [gallery]<img src="image/path" or-wht-generated-by-uploader-here />[gallery] then voila, a beautiful gallery displayed to the user. But when I using a page, there're a simple textarea for the HTML template, and I don't want to rewrite all the wrapper in pure HTML. Reusing the gallery BBCode should be the nicer solution.
 
How we can using BBCode to remove the amount of HTML/js in the template?

BB Code will render back into HTML. This is a pretty pointless endeavor.

I've use the following syntax but not work: {xen:helper bbCode, "gallery", "<div>a.jpg</div><div>b.jpg</div><div>c.png</div>"}

Also, what do you expect this code snippet to do? The BB Code renderer is for the purpose of rendering BB code to HTML. So if you give it HTML as input, what do you expect it to do with that in the first place? Either way, it'll interpret it as text, and therefor render it as text, not as HTML. There's no reason to do {xen:helper bbCode, "gallery", "<div>a.jpg</div><div>b.jpg</div><div>c.png</div>"}, just do <div>a.jpg</div><div>b.jpg</div><div>c.png</div> directly.

[gallery]<img src="image/path" or-wht-generated-by-uploader-here />[gallery]

I don't get this construct either. The whole purpose of BB code is not to use html. Why would you have HTML inside your BB codes?
 
BB Code will render back into HTML. This is a pretty pointless endeavor.
Yes, I know BB Code will render back into HTML. But when I've already write the PHP code for rendering the BB code (think like shortcode in Wordpress) then do you want to reuse the BB code or write in HTML from the scratch?

Also, what do you expect this code snippet to do?
I've already said, its a customized lightbox to show image gallery, it process the inside images, wrap them in some lightbox wrapper, and add js, css on the fly.

In my case, what I want is not <div>a.jpg</div><div>b.jpg</div><div>c.png</div> but

Code:
<div class="container gallery-container">
<div class="wrapper some-level-of-wrapper">
<h4 class="title the-gallery-title"></h4>
<span class="info some-instruction-like-click-image-to-enlarge"></span>
<script type="text/javascript">The script for this gallery</script>

<div>a.jpg</div><div>b.jpg</div><div>c.png</div>

</div></div>

I don't get this construct either. The whole purpose of BB code is not to use html. Why would you have HTML inside your BB codes?
Back to what I have already said, in the front-end, I-as-a-user can simply use the uploader to upload images, then wrap them in [gallery] BB Code, so I can get the gallery without using any HTML code!!!

So now, I-as-a-administrator who use the admin panel but cannot use the simple WYSIWYG editor.

I use the HTML for demostration, it should be
[gallery][img]IMG1[/img][img]IMG2[/img]...[gallery] in the front-end

In the backend, what do you think is simpler?
{xen:helper bbCode, "gallery", "<div><img src="img1" /></div><div><img src="img2" /></div>..."}
or (I dont think this is evenly valid syntax)
{xen:helper bbCode, "gallery", "{xen:helper bbCode, "img", "img1"}{xen:helper bbCode, "img", "img2"}..."}

Also, please note that I am using template HTML syntax in page editor, not the normal general template editing in the Apperance/Style menu. So there're many complex UI element that I don't want to copy and paste each time I use! So a BB code helper, like a shortcode in WP, should be a potential solution.
 
Last edited:
Back
Top Bottom