trait CMS\Shortcode\ShortcodeTrait

This trait adds shortcode parsing functionality to any class. A Shortcode is a QuickApps-specific code that lets you do nifty things with very little effort. Shortcodes can for example print current language code or call specifics plugins/themes functions. For more details please check the Shortcode API documentation.

Basic Usage

This trait is mainly used to parse shortcodes in text contents, this is achieved using the shortcodes() method:

// Some class

use CMS\Shortcode\ShortcodeTrait;

// ...

$text = 'Current language is: {locale /}';
echo $this->shortcodes($text);
// Prints depending on current language code, e.g. "Current language is: en_US"

Some times you would need to scape every shortcode present in your content so they wont be ignored by shortcodes():

$text = 'Current language is: {locale /}';
$textEscaped = $this->escapeShortcodes($text);

echo $this->shortcodes($text);
// Prints "Current language is: en_US"

echo $this->shortcodes($textEscaped);
// Prints "Current language is: {locale /}"

echo $textEscaped;
// Prints "Current language is: {{locale /}}"

QuickAppsCMS provides a very handy shortcode that can be used to escape any shortcode within portions of HTML code in your view templates:

// MyPlugin/Template/MyController/some_action.ctp

<h2>Supported shortcodes are:</h2>
    <li>- {my_shortcode}</li>
    <li>- {another-shortcode}</li>

In the example above, after template is rendered you will get the following HTML code:

<h2>Supported shortcodes are:</h2>
    <li>- {my_shortcode}</li>
    <li>- {another_shortcode}</li>

As you can see {my_shortcode} and {another_shortcode} are ignored and are automatically escaped.


QuickAppsCMS comes with a few built-in shortcodes, check System plugin documentation for more details.

Trait API

CMS\Shortcode\ShortcodeTrait::shortcodes($content, $context = null)

Look for shortcodes in the given text.


Removes all shortcodes from the given content.


Escapes all shortcodes from the given content.


Enables shortcodes feature.


Globally disables shortcodes feature.