The Shortcode API s a simple regex based parser that allows you to replace simple bbcode-like tags within a HTMLText or HTMLVarchar field when rendered into a content.
Examples of shortcode tags:
{shortcode} {shortcode parameter="value"}
Example of escaping shortcodes:
{{shortcode}}
Your shorcode function:
function returnSiteUrl() { return Option::get('siteurl'); }
Add shortcode http://monstra.org
Shortcode::add('siteurl', 'returnSiteUrl');
Your shorcode function:
function foo($attributes) { // Extract extract($attributes); // text if (isset($text)) $text = $text; else $text = ''; // return return $text; }
Add shortcode {foo text="Hello World"}
Shortcode::add('foo', 'foo');
Usage:
{foo text="Hello World"}
Result:
Hello World
Your shorcode function:
function foo($attributes, $content) { // Extract extract($attributes); // text if (isset($color)) $color = $color; else $color = 'black'; // return return '<span style="color:'.$color.'">'.Filter::apply('content', $content).'</span>'; }
Add shortcode {foo color="red"}
Shortcode::add('foo', 'foo');
Usage:
{foo color="red"}Hello World{/foo}
Result:
Hello World
if (Shortcode::exists('foo')) { // do something... }
Shortcode::delete('foo');
Shortcode::clear();
The shortcode parser does not accept braces within attributes. Thus the following will fail:
{foo attribute="{Some value}"}Hello World{/foo}