I am creating a custom BB code where I would like the html to change depending on the value of the {option} parameter. Are {vb:if} functions supported in custom BBCodes?
How to use the {option} parameter in a custom BBCode
Collapse
X
-
Tags: None -
No, there's no way to have conditionals in bbcodes.MARK.B
vBulletin Support
------------
My Unofficial vBulletin 6.0.0 Demo: https://www.talknewsuk.com
My Unofficial vBulletin Cloud Demo: https://www.adminammo.com -
Thank you, Mark. So {option} is just the same as {param} in that it's a replaceable variable and cannot be used to choose between 2 different sets of html?
I assume php and javscript are not allowed either?Comment
-
But you might be able to use Javascript to do the conditional check and output/change something based on the result. Let us know what you're trying to do.Comment
-
I didn't see your post until I posted my last message. You can use Javascript in the BBCode replacement.Comment
-
That's encouraging. I know nothing of javascript, but what I'm trying to do is something like this:
Right now I have a Custom BBCode that is [UPS]123456[/UPS] and that expands to a URL that goes to the UPS web site and shows the tracking info for that number.
The BBCode is:
Code:<a href="http://wwwapps.ups.com/WebTracking/processRequest?HTMLVersion=5.0&Requester=NES&AgreeToTermsAndConditions=yes&tracknum={param}">{param}</a>
I have another similar one for USPS and Fedex, but totally different URLs of course. What I'd like is to combine the BBCodes to a single BBCode called TRACK. e.g.
[TRACK=UPS]123456[/TRACK] This should expand to the UPS URL
[TRACK=Fedex]123456[/TRACK] This should expand to the Fedex URL, etc.Comment
-
Try this.
Replacement:
Code:<a>{param}</a><img src="images/misc/progress3.gif" onload="!function(e){var t='{option}',r=e.previousSibling;/ups/i.test(t)?r.href='http://wwwapps.ups.com/WebTracking/processRequest?HTMLVersion=5.0&Requester=NES&AgreeToTermsAndConditions=yes&tracknum={param}':/fedex/i.test(t)&&(r.href='https://www.fedex.com/apps/fedextrack/?action=track&trackingnumber={param}')}(this);this.parentNode.removeChild(this);" />
Use {option}: Yes
Disable options: All Yes
Ignore "BBCode replacement may not be properly formed" warning when saving. Replace the FedEx tracking URL in the code if needed. Make sure "images/misc/progress3.gif" exists and the path is correct. Note that changing it to a transparent 1x1 image is better. The reason why the Javascript code is in img onload is because using regular <script> tag does not work on Post Quick Reply and Edit Post as they use AJAX and the new post is rendered via innerHTML which does not execute javascript inside <script> tags.Comment
-
Thank you very much! I'll give it a try. I can understand all of it, with the help of google, except the last part:
(this);this.parentNode.removeChild(this);
What is the reason for that?Comment
-
Comment
-
It doesn't seem to work for some reason. {param} becomes a link, but the link has no href. It's not a clickable link. Have you tried this?Comment
-
Does the image path in the img src exist? The JavaScript will not execute if it doesn't.Comment
-
And did you set Use {option} to Yes? Review all what I mentioned in post #7Comment
-
Yes and Yes.
I noticed there's an unmatched parenthesis ")" near the end of your string. I don't see the matching open parenthesis.
.... ?action=track&trackingnumber={param}')}Comment
-
If you get a chance, give it a try and let me know if it works. It seems the javascript isn't being executed. I tried even simplifying the code and it seems to ignore it all. I also see the progress3.gif image to the right of the link, so the RemoveChild isn't working either.
Are you certain that vBulletin doesn't just block javascript within BBCodes? I've seen more posts indicating that js IS blocked, but I can't find anything "official".Last edited by Meestor_X; Sun 20 Sep '15, 9:10am.Comment
-
Do you see any error in the Javascript console? If you paste the js code in http://jsbeautifier.org/ to prettify the script, you will see the matching ')'Comment
Related Topics
Collapse
-
by ActronI want to create a custom bbcode like the standart "code" bbcode with no name.... so if i use the custom bbcode there will only show following without the "Code :" on top:
Code:like
-
Channel: Support Issues & Questions
Mon 7 May '18, 11:00am -
Comment