Is it possible to apply a specific text filter (not a whole text format) to a string in Twig?
(Or at least in template preprocess, if not possible in Twig)
Use case:
I've a special block for hand-picked, trusted editors that allows them to inject unfiltered HTML (for social widgets like Facebook posts, TripAdvisor reviews, etc) into the homepage. Basically it is just a custom content block with a text field, and printed using |raw
to avoid style and script tags being from filtered:
{{ content.body.0['#text']|raw }}
This does already work as expected.
Now I've got the additional requirement to apply the text filter from the LinkIt module on this field. The editors want to provide a link to a node, and the link to the node should be printed using the correct language prefix and the SEO-friendly URL alias. E.g. I've got a text field containing something like
<script src="https://external.com/social_widget.js" async defer>
<div id="#placeholder_social_widget"><!-- External widget does it's magic in here</div>
<script>/* some scripts from us */</script>
<a data-entity-substitution="canonical" data-entity-type="node" data-entity-uuid="whatever-123-abc-def">Link with correct language prefix and SEO-friendly URL-alias</a>
and I want to run the LinkIt replacement on that field and then output it, but without filtering or escaping any of the JS or CSS.