2

I have a Plain Text field used for product names. Some of these product names have a Registration Mark or a Trademark, which needs to be formatted within a superscript.

Here is code within my template:

{{ product.name | replace({'®': '<sup>®</sup>' }) }}

Which publishes this:

Acme ABC Widget<sup>®</sup>

When what I really want to achieve is this:

Acme ABC Widget®

Does Craft persistently render Plain Text fields as raw text? I was hoping Twig filters could extend the use of Craft's Plain Text field.

My preference is to continue using the Plain Text field to avoid additional formatting breaking the layout.

4

You can use the raw Twig filter. Try this:

{{ product.name | replace({'®': '<sup>®</sup>' })|raw }}
3

You wanna escape the product name before replacing.

{{ product.name|escape|replace({'®': '<sup>®</sup>'})|raw }}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.