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.

62 lines
2.1 KiB

9 years ago
  1. # Shortcodes for October CMS
  2. Adds the ability to use shortcodes within October CMS
  3. ### Add new shortcodes
  4. Add the shortcode in the `boot` function of a plugin.
  5. Then, use the provided facade to add new shortcodes in your own plugins:
  6. \Shortcode::add('code', function(ShortcodeInterface $s) {
  7. $text = "<h2>Shortcode Name: {$s->getName()}</h2>";
  8. $text .= "<p>Shortcode Parameter: {$s->getParameter('param', 'Not Found')}</p>";
  9. $text .= "<p>Shortcode Content: {$s->getContent()}</p>";
  10. return $text;
  11. });
  12. The above registration would enable the following shortcode to be used:
  13. [code param="Parameter Value"] Inside Content [/code]
  14. ### Use the shortcode within a page or blog post:
  15. The usual shortcode syntax is supported via the [Thunderer\Shortcode](https://github.com/thunderer/Shortcode) project.
  16. [code]
  17. [code argument="value"]
  18. [code novalue argument=simple other="complex value"]
  19. [code]content[/code]
  20. [code argument="value"]content[/code]
  21. ### Enable shortcodes on all pages
  22. To enable shortcodes on all page rendering, go to **Shortcode Settings** in the admin settings panel and check "Enable Shortcodes on all page rendering".
  23. ### Using filters and functions
  24. If you don't want to enable shortcodes on all page rendering, you can use the built-in filter or function.
  25. To use the `shortcode` filter within a blog post or page, add the `shortcode` filter before any `raw` filtering.
  26. <div class="cp-post-content">{{ post.content_html|shortcode|raw }}</div>
  27. 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:
  28. {% page %}
  29. Becomes:
  30. {{ shortcode(page()) }}
  31. -- or --
  32. {{ page()|shortcode }}
  33. ### Strip Shortcodes
  34. 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:
  35. Event::listen('sensory5.blog.summary', function($content) {
  36. return Str::limit(Html::strip(\Shortcode::strip($content)), 600);
  37. });