1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-17 18:36:39 +02:00

Entries API - shortcodes parsing issue #145 #117

This commit is contained in:
Awilum
2019-06-10 00:13:33 +03:00
parent 224e5a228a
commit a9cca65f98
7 changed files with 56 additions and 6 deletions

View File

@@ -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;
};

View File

@@ -0,0 +1,47 @@
<?php
/**
* @package Flextype
*
* @author Sergey Romanenko <hello@romanenko.digital>
* @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);
}
}

View File

@@ -1,6 +1,6 @@
{% extends "themes/default/templates/partials/base.html" %}
{% block content %}
{{ entry.content|raw }}
{{ entry.content|shortcode|raw}}
<img src="image/{{ entry.slug }}/{{ entry.image }}?w=670&dpr=2" alt="">
{% endblock %}

View File

@@ -3,6 +3,6 @@
{% block content %}
<h1>{{ entry.title }}</h1>
<div class="blog-post">
{{ entry.content|raw }}
{{ entry.content|shortcode|raw}}
</div>
{% endblock %}

View File

@@ -9,7 +9,7 @@
{% for entry in entries_fetch_all('blog', 'date', 'DESC') %}
<a href="{{ entry.slug }}" class="blog-post">
<h3>{{ entry.title }}</h3>
<p>{{ entry.summary|raw }}</p>
<p>{{ entry.summary|shortcode|raw}}</p>
<div>{{ entry.date }}</div>
</a>
{% endfor %}

View File

@@ -1,5 +1,5 @@
{% extends "themes/default/templates/partials/base.html" %}
{% block content %}
{{ entry.content|raw }}
{{ entry.content|shortcode|raw}}
{% endblock %}

View File

@@ -2,12 +2,12 @@
{% block content %}
{{ entry.content|raw }}
{{ entry.content|shortcode|raw}}
{% for entry in entries_fetch_all('blog', 'date', 'DESC', 0, 3) %}
<a href="{{ entry.slug }}" class="blog-post">
<h3>{{ entry.title }}</h3>
<p>{{ entry.summary|raw }}</p>
<p>{{ entry.summary|shortcode|raw}}</p>
<div>{{ entry.date }}</div>
</a>
{% endfor %}