Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically perform |raw filtering in |shortcodes filter in Twig #123

Open
dmik opened this issue Jul 13, 2024 · 0 comments
Open

Automatically perform |raw filtering in |shortcodes filter in Twig #123

dmik opened this issue Jul 13, 2024 · 0 comments

Comments

@dmik
Copy link

dmik commented Jul 13, 2024

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

{{ '[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):

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

If used with |raw like this:

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

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

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant