diff --git a/flextype/bootstrap.php b/flextype/bootstrap.php index 5a1ec216..8106268b 100755 --- a/flextype/bootstrap.php +++ b/flextype/bootstrap.php @@ -316,6 +316,9 @@ $flextype['view'] = function ($container) { // Add Global Vars Twig Extension $view->addExtension(new GlobalVarsTwigExtension($container)); + // Add Global Shortcodes Twig Extension + $view->addExtension(new ShortcodesTwigExtension($container)); + // Return view return $view; }; diff --git a/flextype/twig/ShortcodesTwigExtension.php b/flextype/twig/ShortcodesTwigExtension.php new file mode 100644 index 00000000..f50e353c --- /dev/null +++ b/flextype/twig/ShortcodesTwigExtension.php @@ -0,0 +1,47 @@ + + * @link http://romanenko.digital + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flextype; + +class ShortcodesTwigExtension extends \Twig_Extension +{ + + /** + * Flextype Dependency Container + */ + private $flextype; + + /** + * Constructor + */ + public function __construct($flextype) + { + $this->flextype = $flextype; + } + + /** + * Callback for twig. + * + * @return array + */ + public function getFilters() + { + return [ + new \Twig_SimpleFilter('shortcode', [$this, 'shortcode']), + ]; + } + + public function shortcode(string $value) : string + { + return $this->flextype->shortcodes->process($value); + } +} diff --git a/site/themes/default/templates/about.html b/site/themes/default/templates/about.html index 756f069c..becdff15 100644 --- a/site/themes/default/templates/about.html +++ b/site/themes/default/templates/about.html @@ -1,6 +1,6 @@ {% extends "themes/default/templates/partials/base.html" %} {% block content %} - {{ entry.content|raw }} + {{ entry.content|shortcode|raw}} {% endblock %} diff --git a/site/themes/default/templates/blog-post.html b/site/themes/default/templates/blog-post.html index 63e7fb7b..bfc1267e 100644 --- a/site/themes/default/templates/blog-post.html +++ b/site/themes/default/templates/blog-post.html @@ -3,6 +3,6 @@ {% block content %}

{{ entry.title }}

- {{ entry.content|raw }} + {{ entry.content|shortcode|raw}}
{% endblock %} diff --git a/site/themes/default/templates/blog.html b/site/themes/default/templates/blog.html index 599a1804..35ab6765 100644 --- a/site/themes/default/templates/blog.html +++ b/site/themes/default/templates/blog.html @@ -9,7 +9,7 @@ {% for entry in entries_fetch_all('blog', 'date', 'DESC') %}

{{ entry.title }}

-

{{ entry.summary|raw }}

+

{{ entry.summary|shortcode|raw}}

{{ entry.date }}
{% endfor %} diff --git a/site/themes/default/templates/default.html b/site/themes/default/templates/default.html index 835189c2..595e5773 100644 --- a/site/themes/default/templates/default.html +++ b/site/themes/default/templates/default.html @@ -1,5 +1,5 @@ {% extends "themes/default/templates/partials/base.html" %} {% block content %} - {{ entry.content|raw }} + {{ entry.content|shortcode|raw}} {% endblock %} diff --git a/site/themes/default/templates/home.html b/site/themes/default/templates/home.html index 1e42eb14..4c63a924 100644 --- a/site/themes/default/templates/home.html +++ b/site/themes/default/templates/home.html @@ -2,12 +2,12 @@ {% block content %} - {{ entry.content|raw }} + {{ entry.content|shortcode|raw}} {% for entry in entries_fetch_all('blog', 'date', 'DESC', 0, 3) %}

{{ entry.title }}

-

{{ entry.summary|raw }}

+

{{ entry.summary|shortcode|raw}}

{{ entry.date }}
{% endfor %}