#1 February 3, 2015 11:41pm

taylorn16
Member
Registered: February 3, 2015
Posts: 3

Parsing "Shortcodes" with WordPress-like Syntax

First of all, I would like to extend a special thank-you to the team at FastSpot for keeping BigTree an open-source project. I was in love as soon as I downloaded my first copy and am currently using it for a client project. So thank you for taking the extra time it takes to develop for the open-source community. You're awesome.

If it wasn't clear, this is my first post, so bear with me.

My question is as the title says: has anyone had a need to implement a WordPress-like shortcode parser for the content pieces of their site? I don't exactly feel like writing my own library for a few shortcodes just for buttons and some special image styles. I'm sure someone has found a solution to this problem before.

Has anyone used a PHP library for this in the past that they would recommend? Would it be easier accomplished by modifying the TinyMCE editor?

What I have in mind is just something basic like:
[button url="http://google.com" color="red"]Click Me![/button] would transform into <a href="http://google.com" class="btn btn--red">Click Me!</a>

Thanks guys!

Offline

#2 February 4, 2015 11:17am

timbuckingham
Administrator
From: Baltimore, MD
Registered: April 2, 2012
Posts: 974

Re: Parsing "Shortcodes" with WordPress-like Syntax

I know in the past we've created a shortcode parser for importing WordPress posts into a BigTree-based blog, but I don't think we've ever implemented a TinyMCE interface for creating short codes inside the WYSIWYG.

We've done snippets in the past that are replaced, though. For that we usually use TinyMCE's built in "template" support:
http://www.tinymce.com/wiki.php/Plugin:template

To do that you can place a copy of /core/admin/layouts/_html-field-loader.php in /custom/admin/layouts/ and modify it to your liking. We usually add to TinyMCE's extended_valid_elements for custom tags (i.e. <super-button data-link="{$link}">{$title}</super-button>) and then either use regex or PHP's admittedly terrible DOMDocument support to do the replacement in front end templates.

Offline

#3 February 4, 2015 12:20pm

taylorn16
Member
Registered: February 3, 2015
Posts: 3

Re: Parsing "Shortcodes" with WordPress-like Syntax

Exactly what I needed. Thanks!

Offline

Board footer

Powered by FluxBB

The Discussion Forum is not available on displays of this size.