Files
shortcode-plugin/README.md

93 lines
2.9 KiB
Markdown
Raw Normal View History

2015-10-23 12:41:54 -04:00
# Shortcodes for October CMS
2015-10-23 10:04:50 -04:00
Adds the ability to use shortcodes within October CMS
2015-10-23 12:41:54 -04:00
### Add new shortcodes
Add the shortcode in the `boot` function of a plugin.
Then, use the provided facade to add new shortcodes in your own plugins:
\Shortcode::add('code', function(ShortcodeInterface $s) {
$text = "<h2>Shortcode Name: {$s->getName()}</h2>";
$text .= "<p>Shortcode Parameter: {$s->getParameter('param', 'Not Found')}</p>";
$text .= "<p>Shortcode Content: {$s->getContent()}</p>";
return $text;
});
The above registration would enable the following shortcode to be used:
[code param="Parameter Value"] Inside Content [/code]
### Use the shortcode within a page or blog post:
2015-11-25 15:29:27 -05:00
The usual shortcode syntax is supported:
2015-10-23 12:41:54 -04:00
[code]
[code argument="value"]
[code novalue argument=simple other="complex value"]
[code]content[/code]
[code argument="value"]content[/code]
2015-11-25 15:29:27 -05:00
For nested shortcodes, you must call the `parse` method within the function.
2015-10-23 12:41:54 -04:00
### Enable shortcodes on all pages
To enable shortcodes on all page rendering, go to **Shortcode Settings** in the admin settings panel and check "Enable Shortcodes on all page rendering".
### Using filters and functions
If you don't want to enable shortcodes on all page rendering, you can use the built-in filter or function.
To use the `shortcode` filter within a blog post or page, add the `shortcode` filter before any `raw` filtering.
<div class="cp-post-content">{{ post.content_html|shortcode|raw }}</div>
To use the `shortcode` function within a layout and against the October CMS `page` tag, change the `page` tag from a token to a function:
{% page %}
Becomes:
{{ shortcode(page()) }}
-- or --
{{ page()|shortcode }}
### Strip Shortcodes
2015-10-27 15:58:45 -04:00
You can strip shortcodes from text using the `Shortcode::strip` function.
\Shortcode::strip($content);
2015-10-23 12:41:54 -04:00
2015-10-23 16:00:25 -04:00
### Dependency Issues with Service Provider and Facade
When using this plugin within another plugin, you may find that the Service Provider and/or Facade are not loaded if the dependant plugin loads prior to the Shortcode plugin.
In that case, you can either explicitly register the Shortcode plugin within the `boot` method of the plugin. For example:
// Add Shortcode Service provider
App::register('\Sensory5\Shortcode\Classes\ServiceProvider');
// Add Shortcode facade
$alias = AliasLoader::getInstance();
$alias->alias('Shortcode', '\Sensory5\Shortcode\Classes\Facade');
Or, you can add the Service Provider and Facade into the `config/app.php` file at the root of the OctoberCMS site. For example:
'providers' => array_merge(include(base_path().'/modules/system/providers.php'), [
'System\ServiceProvider',
'Sensory5\Shortcode\Classes\ServiceProvider'
]),
'aliases' => array_merge(include(base_path().'/modules/system/aliases.php'), [
'Shortcode' => 'Sensory5\Shortcode\Classes\Facade'
]),