# Grav Shortcode Core Plugin ## About The **Shortcode Core** plugin allow for the development of simple yet powerful shortcode plugins that utilize the common format utilized by **WordPress** and **BBCode**. The core plugin loads the libraries required and fires a new event that other plugins can use. It also provides a mechanism for adding CSS/JS assets that are cached so that shortcodes can work effectively even when the processed page content is cached. This ensures that shortcodes are only processed once and will not impact performance by doing unnecessary work on every page. This plugin uses the [Thunderer Advanced shortcode engine](https://github.com/thunderer/Shortcode). For more information please check out that repo on GitHub. ## Available Shortcodes The Shortcode Core plugin provides the following built-in shortcodes: ### Text Formatting - **[Underline](#underline)** - Underline text - **[Size](#font-size)** - Change font size - **[Color](#color)** - Change text color - **[Mark](#mark)** - Highlight/mark text ### Text Alignment - **[Left](#left-align)** - Left align text - **[Center](#center-align)** - Center align text - **[Right](#right-align)** - Right align text ### Containers - **[Div](#div)** - Wrap content in a div with classes/id - **[Span](#span)** - Wrap content in a span with classes/id - **[Columns](#columns)** - Create CSS columns - **[Details](#detailssummary)** - Collapsible content sections ### Content Elements - **[Headers](#headers)** - H1-H6 with classes/id - **[Figure](#figure)** - Figure with caption - **[Notice](#notice)** - Notice/alert boxes - **[Section](#section)** - Named content sections ### Special Functions - **[Raw](#raw)** - Prevent shortcode processing - **[Safe-Email](#safe-email)** - Encode email addresses - **[FontAwesome](#fontawesome)** - Insert FontAwesome icons - **[Language](#language)** - Language-specific content - **[Lorem](#lorem-ipsum)** - Generate lorem ipsum text ## Quick Example ``` This is some [u]bb style underline[/u] and not much else [center]This is centered[/center] This is [size=30]bigger text[/size] and this is [color=blue]blue text[/color] ``` This example functionality is provided with the **Shortcode Core** plugin to provide some functionality that is not available in traditional markdown but is standard **BBCode** used in many form platforms. You can see how the syntax is just a simple open and close element using square brackets. This will render:  ## Installation Typically a plugin should be installed via [GPM](http://learn.getgrav.org/advanced/grav-gpm) (Grav Package Manager): ``` $ bin/gpm install shortcode-core ``` Alternatively it can be installed via the [Admin Plugin](http://learn.getgrav.org/admin-panel/plugins) > NOTE: If you install a shortcode plugin such as [grav-plugin-shortcode-ui](https://github.com/getgrav/grav-plugin-shortcode-ui) it may have this core plugin configured as a dependency and install it automatically. ## Configuration Defaults The **Shortcode Core** plugin only has a few options to configure. The default values are: ```yaml enabled: true active: true active_admin: true admin_pages_only: true parser: regular include_default_shortcodes: true css: notice_enabled: true custom_shortcodes: fontawesome: load: true url: '//maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css' v5: false ``` * `enabled: true|false` toggles if the shortcodes plugin is turned on or off * `active: true|false` toggles if shortcodes will be enabled site-wide or not * `active_admin: true|false` toggles if shortcodes will be processed in the admin plugin * `admin_pages_only: true|false` toggles if admin should only process shortcodes for Grav pages * `parser: wordpress|regex|regular` let's you configure the parser to use * `include_default_shortcodes: true|false` toggle the inclusion of shortcodes provided by this plugin * `custom_shortcodes:` the path to a directory where you can put your custom shortcodes (e.g. `/user/custom/shortcodes`) * `fontawesome.load: true|false` toggles if the fontawesome icon library should be loaded or not * `fontawesome.url:` the CDN Url to use for fontawesome * `v5:` Version 5 flag as it requires some additional logic > NOTE: In previous versions the `wordpress` parser was preferred. However with version `2.4.0`, the `regex` parser is now default. If you have saved configuration, you should manually change this to `regex` or you may receive errors or bad output. ## Configuration Modifications The best approach to make modifications to the core plugin settings is to copy the `shortcode-core.yaml` file from the plugin into your `user/config/plugins/` folder (create it if it doesn't exist). You can modify the settings there. > NOTE: If you have the admin plugin installed, you can make modifications to the settings via the **Plugins** page and it will create that overridden file automatically. ## Per-Page Configuration Sometimes you may want to only enable shortcodes on a _page-by-page_ basis. To accomplish this set your plugin defaults to: ```yaml enabled: true active: false ``` This will ensure the plugin is loaded, but not **active**, then on the page you wish to process shortcodes on simply add this to the page header: ```yaml shortcode-core: active: true ``` This will ensure the shortcodes are processed on this page only. You can also change the parser on a particular page with the following: ```yaml shortcode-core: parser: regex ``` ## Building Your Own Shortcodes You can add your own shortcodes **without writing a PHP class or a plugin** using the **Shortcode Builder**. Each custom shortcode is backed by either a Twig template file or a short inline output snippet, and you wire it up in config or on the dedicated **Shortcode Builder** tab of the plugin settings (which works in both the classic admin and Admin Next). This is the recommended way to do the dynamic things people used to reach for Twig-in-content to do. In Grav 2.0, Twig in page content is disabled by default for [security reasons](https://learn.getgrav.org/content/twig-in-content); a shortcode keeps the logic in trusted code (a template or admin-authored config) while the author just writes a clean tag. The plugin ships with two starter examples you can edit or remove — a template-backed `[callout]` and an inline `[badge]`. They are defined under `shortcodes:` in `user/config/plugins/shortcode-core.yaml`: ```yaml shortcodes: - name: callout template: 'shortcodes/callout.html.twig' - name: badge output: '{{ content }}' ``` * **`name`** — the shortcode tag. `callout` makes `[callout]…[/callout]` available. * **`template`** — a Twig template path (resolved through Grav's normal Twig lookup, so it can live in your theme or a plugin). Takes precedence over `output` when both are set. * **`output`** — an inline Twig snippet, handy for simple one-liners that don't warrant a file. Inside the template or snippet you have three variables: | Variable | Description | | --- | --- | | `params` | the shortcode's parameters, e.g. `params.style` for `[badge style="success"]` | | `content` | the content between the opening and closing tags | | `shortcode` | the raw shortcode object, for advanced use | A template-backed example (`templates/shortcodes/callout.html.twig` in your theme): ```twig