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.

92 lines
2.9 KiB

9 years ago
9 years ago
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:
  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. For nested shortcodes, you must call the `parse` method within the function.
  22. ### Enable shortcodes on all pages
  23. To enable shortcodes on all page rendering, go to **Shortcode Settings** in the admin settings panel and check "Enable Shortcodes on all page rendering".
  24. ### Using filters and functions
  25. If you don't want to enable shortcodes on all page rendering, you can use the built-in filter or function.
  26. To use the `shortcode` filter within a blog post or page, add the `shortcode` filter before any `raw` filtering.
  27. <div class="cp-post-content">{{ post.content_html|shortcode|raw }}</div>
  28. 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:
  29. {% page %}
  30. Becomes:
  31. {{ shortcode(page()) }}
  32. -- or --
  33. {{ page()|shortcode }}
  34. ### Strip Shortcodes
  35. You can strip shortcodes from text using the `Shortcode::strip` function.
  36. \Shortcode::strip($content);
  37. ### Dependency Issues with Service Provider and Facade
  38. 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.
  39. In that case, you can either explicitly register the Shortcode plugin within the `boot` method of the plugin. For example:
  40. // Add Shortcode Service provider
  41. App::register('\Sensory5\Shortcode\Classes\ServiceProvider');
  42. // Add Shortcode facade
  43. $alias = AliasLoader::getInstance();
  44. $alias->alias('Shortcode', '\Sensory5\Shortcode\Classes\Facade');
  45. Or, you can add the Service Provider and Facade into the `config/app.php` file at the root of the OctoberCMS site. For example:
  46. 'providers' => array_merge(include(base_path().'/modules/system/providers.php'), [
  47. 'System\ServiceProvider',
  48. 'Sensory5\Shortcode\Classes\ServiceProvider'
  49. ]),
  50. 'aliases' => array_merge(include(base_path().'/modules/system/aliases.php'), [
  51. 'Shortcode' => 'Sensory5\Shortcode\Classes\Facade'
  52. ]),