BBcode inside BBcode changing layout

Get help developing custom BBCodes or request one.
Post Reply
User avatar
Kami-sama
Registered User
Posts: 104
Joined: Sat May 26, 2018 3:07 pm

BBcode inside BBcode changing layout

Post by Kami-sama » Fri Jul 13, 2018 7:54 pm

Hey! I have this simple code for post layout: [tema={TEXT1?}]{TEXT2}[/tema]
The structure of this BBCode is:

Code: Select all

<br/><div class="temaBG"><div class="temaTt">{TEXT1}</div>
<div class="temaCon">{TEXT2}</div></div><br/>
Result is:
Image


I want to create such OPTIONAL result:
Image

I have tried to create second BBCode: [tema2={TEXT1?}]{TEXT2}[/tema2]
With code like this:

Code: Select all

</div><div class="temaTt">{TEXT1}</div>
<div class="temaCon">{TEXT2}
In post that would look like:

Code: Select all

[tema=Test Topic]
Test Content
[tema2=Tittle 2]
Topic Content 2
[/tema2]
[/tema]
But that does not work. tema2 BBCode is ignored. Any ideas if it's possible get this kind of result?

User avatar
JoshyPHP
Code Contributor
Posts: 960
Joined: Mon Jul 11, 2011 12:28 am

Re: BBcode inside BBcode changing layout

Post by JoshyPHP » Tue Jul 17, 2018 9:59 am

BBCode templates are evaluated individually and a BBCode that starts with </div> won't close the previous element. That's a good thing because otherwise, a post that starts with a few [tema2] would break the layout for the rest of the page.

There are ways to achieve what you're trying to do but I don't recommend it. I think that the following definitions could work:

Code: Select all

[tema title={TEXT1?} #createChild=tema2]{TEXT2}[/tema]

Code: Select all

<div class="temaBG">
	<xsl:if test="@title">
		<div class="temaTt"><xsl:value-of select="@title"/></div>
	</xsl:if>
	<xsl:apply-templates/>
</div>

Code: Select all

[tema2 title={TEXT1?} #closeParent=tema2 #requireParent=tema]{TEXT2}[/tema2]

Code: Select all

<xsl:if test="@title">
	<div class="temaTt"><xsl:value-of select="@title"/></div>
</xsl:if>
<div class="temaCon"><xsl:apply-templates/></div>
IMO, you're better off using a BBCode for the temaBG element and a second BBCode for the pair of temaTt and temaCon elements. It's sound and forward compatible. Similarly, I'd recommend using expressive names otherwise you'll end up with tema3, tema4, etc... and it will be hard to remember how to use them.
I wrote the thing that does BBCodes in 3.2.

User avatar
Kami-sama
Registered User
Posts: 104
Joined: Sat May 26, 2018 3:07 pm

Re: BBcode inside BBcode changing layout

Post by Kami-sama » Tue Jul 17, 2018 11:53 am

Thank you! This is exactly what I was looking for, are there any tutorials how to use xsl?
I would like to understand how this works. And also, is there an ELSE option available for the IF?
Last edited by Mick on Tue Jul 17, 2018 12:15 pm, edited 1 time in total.
Reason: Removed unnecessary quoting.

User avatar
JoshyPHP
Code Contributor
Posts: 960
Joined: Mon Jul 11, 2011 12:28 am

Re: BBcode inside BBcode changing layout

Post by JoshyPHP » Tue Jul 17, 2018 12:16 pm

You can read the XSLT 1.0 specs although not all of XSLT is supported (both for technical and safety reasons) so I'd recommend limiting your usage to conditionals and the xsl:value-of and xsl:apply-templates elements. Again, I advise against creating complicated markup or a complicated BBCode definition.

There's no xsl:else but you can use xsl:choose, xsl:when, and xsl:otherwise together.
I wrote the thing that does BBCodes in 3.2.

User avatar
Mick
Support Team Member
Support Team Member
Posts: 20134
Joined: Fri Aug 29, 2008 9:49 am
Location: Cardiff

Re: BBcode inside BBcode changing layout

Post by Mick » Tue Jul 17, 2018 12:16 pm

There are loads of xsl tutorials available via google.
"The more connected we get the more alone we become" - Kyle Broflovski

There are no ‘threads’ in phpBB, they are topics.

User avatar
Kami-sama
Registered User
Posts: 104
Joined: Sat May 26, 2018 3:07 pm

Re: BBcode inside BBcode changing layout

Post by Kami-sama » Tue Jul 17, 2018 2:45 pm

JoshyPHP wrote:
Tue Jul 17, 2018 12:16 pm
You can read the XSLT 1.0 specs although not all of XSLT is supported (both for technical and safety reasons) so I'd recommend limiting your usage to conditionals and the xsl:value-of and xsl:apply-templates elements. Again, I advise against creating complicated markup or a complicated BBCode definition.

There's no xsl:else but you can use xsl:choose, xsl:when, and xsl:otherwise together.
Oh thank you! I don't intend to have any overcomplicated BBcodes. This will be the only one probably :D and optional part used only by admins. So I think it will be fine, but thank you for warnings!

I'm still pretty new with this, very eager to learn more!

Post Reply

Return to “Custom BBCode Development and Requests”

Who is online

Users browsing this forum: No registered users and 5 guests