You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Patrick Ward 68bb5b0e24 Initial shortcode implementation 9 years ago
classes Initial shortcode implementation 9 years ago
models Initial shortcode implementation 9 years ago
tests Initial shortcode implementation 9 years ago
.gitignore Initial commit 9 years ago
LICENSE Initial commit 9 years ago
Plugin.php Initial shortcode implementation 9 years ago
README.md Initial shortcode implementation 9 years ago
composer.json Initial shortcode implementation 9 years ago
composer.lock Initial shortcode implementation 9 years ago

README.md

Shortcodes for October CMS

Adds the ability to use shortcodes within October CMS

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:

The usual shortcode syntax is supported via the Thunderer\Shortcode project.

[code]
[code argument="value"]
[code novalue argument=simple other="complex value"]
[code]content[/code]
[code argument="value"]content[/code]

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

You can strip shortcodes from text using the Shortcode::strip function. For example, when using with the Sensory5\BlogExtension plugin, you can strip shortcodes from the summary using the following code:

Event::listen('sensory5.blog.summary', function($content) {
    return Str::limit(Html::strip(\Shortcode::strip($content)), 600);
});