getgrav / getgrav/grav-plugin-shortcode-core

Automatically perform `|raw` filtering in `|shortcodes` filter in Twig

Open
#123 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
47
Forks
17
PR merge metrics
No merged PRs in 30d

Description

According to the documentation, the `|shortcodes` Twig filter is intended to use shortcodes in Twig templates. However, it will never work without also using the `|raw` filter because Twig will escape all HTML markup (with either `&XX` notation or with double quotes around the expanded string).

Since the shortcodes (almost?) always imply generating some HTML, it actually makes no sense to use them without the `|raw` filter in Twig — nothing will work. And this is not even mentioned in the README.

**How to reproduce**:

Just put something like

```twig
{{ '[fa=cog /]'|shortcodes }}
```

somewhere in e.g. `base.html.twig`. This will generate the following "broken" HTML (that will be rendered as HTML source instead of a FA icon in this example):

```html
<i class="fa fa-cog"></i>
```

If used with `|raw` like this:

```twig
{{ '[fa=cog /]'|shortcodes|raw }}
```

it will generate the correct output that renders the icon properly:

```html

```

Perhaps, if, for some reason, keeping the current behavior is needed (though I can't come up with such a use case), a new filter `shortcodes_raw` may be introduced (and documented in README). However, I think it really makes sense to just always pipe `|shortcodes` output via `|raw` internally.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.