12

Escape single lines as strings: {{ '{% set foo = "bar" %}' }} Use autoescape to escape multiple lines, optionally specifying a syntax (see docs): {% autoescape %} {% if foo != "bar" %} {% set foo = "bar" %} {% endif %} {% endautoescape %} Use verbatim to treat multiple lines as raw text: {% verbatim %} {% if foo != "bar" %} ...


11

The difference between "raw" and "escape" is sometimes confusing... Try this instead: {{ element.blockContent|e }} escape: The escape filter escapes a string for safe insertion into the final output. raw: The raw filter marks the value as being "safe", which means that in an environment with automatic escaping enabled this variable will not be ...


7

For what it's worth, the problem was due to a mistake on my part: the field in question had been set up as Rich Text, and then switched to Plain Text. I guess the original HTML had been encoded going into the database when the field was still Rich Text, and so was already entity-encoded before it even reached the template. When I pasted the HTML in question ...


5

After trial and error I figured out you can escape characters using double backslash. {{ article.postDate.format('j\\<\\s\\u\\p\\>S\\<\\/\\s\\u\\p\\> F Y') | raw }} Outputs: 14<sup>th</sup> January 2016 In search of documentation I found a mention of double-escaping regular expressions due to Twig auto-escaping \. At this point I'...


3

I would use a combination of things: Twig's replace filter to convert ä to ae etc. Twig's convert_encoding filter to eliminate any remaining non-ascii characters Craft's kebab filter to do its thing and of course wrap the thing up in a macro {% macro ascii_kebab(s) %} {{ s | replace({ 'ä': 'ae' }) | convert_encoding('ASCII', 'UTF-8'...


3

Try the Twig date filter instead: {{ article.postDate|date('jS F Y') }} to wrap the ordinal in <sup>: {{ article.postDate|date('j') }}<sup>{{ article.postDate|date('S') }}</sup> {{ article.postDate|date('F Y') }} if you think it's to ugly for use in your templates, consider "hiding" it in a macro.


2

You could use Twig's replace filter on output: {{ entry.richtext_field_handle|replace('&': '&amp;') }} At first glance I couldn't find a Redactor setting which would help you, but you might want to check yourself, or even write a Redactor plugin.


2

You forgot to remove the outer single quotes in your first example <iron-media-query query="(min-width: 600px)" query-matches="{{'{{queryMatches}}'}}"> Try the raw filter if that doesnt work. More info on it here


2

Found the answer. I just had to do entry.title|raw I had tried this before, but silly me had done it to the wrong heading, so I never saw it change! :D


2

The only way I can see this happening is if the field was originally a Rich Text Field, the content was entered, then the field type was swapped to a plain text field. If that's the case, the Rich Text Field would have encoded the entities and saved them into the database.


1

You can use Craft's |ascii Twig Filter, which was added in Craft 3.1.25, for this: {{ entry.title|ascii }}


1

As it happens, this solved my issue: {{ personfirstandlastname|replace({'\'':''}) }} EDIT To clarify, this isn't a valid Twig object: {'\'',''} ... while this is: {'\'':''}


1

If you're using Craft 3, the Typogrify plugin will do the <sup> on ordinal numbers automatically for you.


1

You can do this with the Luke Holder's Inflect plugin. Which method to use would depend on how you want the resulting text to look. I'd use {{ myTextField|slugify }} to get a string that looks like this "this-is-my-class", since I only use lowercase and hyphenate class/id names.


1

I finally found a way to do that using the "TwigPCRE" Craft plugin: |preg_replace('/&(?!(?:[a-z]+|#x?\d+);)/', '&amp;')|raw This will replace all unescaped & characters which are not part of something else.


Only top voted, non community-wiki answers of a minimum length are eligible