Nov 22, 2009

How To #4: Custom BBCodes For This Board (Pptions) - More than one of them

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > How-To's and Tutorials > Programming > HTML, XML and other Markup Languages

How To #4: Custom BBCodes For This Board (Pptions) - More than one of them

vizskywalker
So far m^e has made us aware of two variables for custom BBcodes: {option} and {content}. But what if you want to have multiple options for a tag, like, maybe foreground color and background color?

To do this all it takes is a simple php script.

If you remember parameters from DOS, it is jsut one list of words or symbols separated by spaces. Contrary to popular belief, this parameter list is one large variable in a program that gets parsed into smaller variables. That is exactly what we do for multiple options.

As an example, I'm going to use a simple highlight command (I don't know if this is the one m^e uses, but it is close enough for our purposes).

The TAG looks like this (angle brackets replace square brackets): <HIGHLIGHT = color>stuff you want highlighted</HIGHLIGHT>

The code for this looks like so:
<span style="background-color: {option}">{content}</span>

But if what if we want to edit the foreground color as well?

First create your single string of parameters separated by a space for the tag:
<HIGHLIGHT = backcolor forecolor>content</HIGHLIGHT>

Now for the code, simply use a php script and split the parameter list:
CODE
<?php
$param = {option}; //place the options in param
list($fore, $back) = split(" ", $param); //split the parameters
echo "<span style="color: $back; background-color: $fore;">{content}</span>
?>"; //send the style to the browser


It's that simple! If you want to allow the second parameter to have a default value then insert this code before echoing the span
CODE
if (!$back) {
$back = "black";
}

 

 

 


Comment/Reply (w/o sign-up)

vujsa
Nice explaination of how to do a BBC highlight tag with more than one option.

I don't actually use IPB, so I don't need the specific code but the idea works for many needs.

Just one question:
QUOTE (vizskywalker)
<span style="color: $back; background-color: $fore;">
Seems off to me.

Shouldn't it read:
<span style="color: $fore; background-color: $back;">

A few more posts on Custom BBC codes for IPB, and we'll have to add a subforum. laugh.gif

Keep up the good work.

vujsa

 

 

 


Comment/Reply (w/o sign-up)

vizskywalker
Um, yes, you are absolutely right, it should be
CODE
<span style="color: $fore; background-color: $back;">

And I wouldn't mind a subforum on this as long as people used the information to create custom BBcodes.

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)


See Also,

*SIMILAR VIDEOS*
Searching Video's for howto, 4, custom, bbcodes, board, options
advertisement



How To #4: Custom BBCodes For This Board (Pptions) - More than one of them

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com