Class ShortcodeParser
A simple parser that allows you to map BBCode-like "shortcodes" to an
arbitrary callback.
Shortcodes can take the form:
[shortcode]
[shortcode attributes="example" /]
[shortcode]enclosed content[/shortcode]
Methods summary
public static
ShortcodeParser
|
#
get( string $identifier = 'default' )
Get the ShortcodeParser instance that is attached to a particular
identifier.
Get the ShortcodeParser instance that is attached to a particular
identifier.
Parameters
- $identifier
- string $identifier Defaults to "default".
Returns
|
public static
ShortcodeParser
|
|
public static
|
#
set_active( string $identifier )
Set the identifier to use for the current active/default ShortcodeParser instance.
Set the identifier to use for the current active/default ShortcodeParser instance.
Parameters
- $identifier
- string $identifier
|
public
|
#
register( string $shortcode, callable $callback )
Register a shortcode, and attach it to a PHP callback.
Register a shortcode, and attach it to a PHP callback.
The callback for a shortcode will have the following arguments passed to it:
- Any parameters attached to the shortcode as an associative array (keys are
lower-case). - Any content enclosed within the shortcode (if it is an enclosing
shortcode). Note that any content within this will not have been parsed, and can
optionally be fed back into the parser. - The ShortcodeParser instance
used to parse the content. - The shortcode tag name that was matched within the
parsed content.
Parameters
- $shortcode
- string $shortcode The shortcode tag to map to the callback - normally in
lowercase_underscore format.
- $callback
- callback $callback The callback to replace the shortcode with.
|
public
boolean
|
#
registered( string $shortcode )
Check if a shortcode has been registered.
Check if a shortcode has been registered.
Parameters
- $shortcode
- string $shortcode
Returns
boolean bool
|
public
|
#
unregister( string $shortcode )
Remove a specific registered shortcode.
Remove a specific registered shortcode.
Parameters
- $shortcode
- string $shortcode
|
public
|
#
clear( )
Remove all registered shortcodes.
Remove all registered shortcodes.
|
public
string
|
#
parse( string $content )
Parse a string, and replace any registered shortcodes within it with the
result of the mapped callback.
Parse a string, and replace any registered shortcodes within it with the
result of the mapped callback.
Parameters
Returns
string string
|
Magic methods summary
Properties summary
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the
Silverstripe Forums to ask development related questions.
-