Skip to main content
18 votes

Limit text when output richtext

No need for a plugin, just use twig's slice filter, combined with the striptags filter. I've thrown in the default filter for good measure, in case the body is empty for some reason. {{ entry.body|...
Adam Menczykowski's user avatar
13 votes

Best method of text truncating

Doesn't answer the specific question but based on the title in search results it might be helpful for anyone just wanting to truncate a string: {{ entry.title | length > 75 ? entry.title | slice(0,...
Clive Portman's user avatar
12 votes

Image alignment and size in Redactor 2

No need for a plugin. Just add: "imageResizable": true, "imagePosition": true, to your chosen redactor config file i.e. (/craft/config/redactor/standard.json)
Rattikarl's user avatar
  • 393
5 votes

Is it possible to use Twig in a Rich Text Field?

For those bumping into this old-ish question and looking for a similar solution: Andrew Welch has recently released a plugin that allows you to pull field values from a globalset. https://github.com/...
simonswiss's user avatar
5 votes
Accepted

Removing P tag's in rich text area's

Seems like a simple striptags filter would do nicely in this case: <h1>{{ entry.titleField|striptags('<strong><em><br>')|raw }}</h1> If you're having issues with ...
Mats Mikkel Rummelhoff's user avatar
4 votes

Rich-Text/Redactor hyperlink classes

For Craft 3 using Redactor 3, I have managed to create a small redactor plugin that toggles a class on all the links selected in redactor. Here is how I did it. Create your folders. Create a folder ...
Martin Stigzelius's user avatar
4 votes
Accepted

How can I dynamically remove some unwanted formatting tags inside rich text fields?

Not a "real" answer because it won't fix your actual content, but I wrote a plugin that would make it easy to remedy your issue on the front end (i.e. in the template) – To remove all <h1> and &...
Mats Mikkel Rummelhoff's user avatar
4 votes
Accepted

YouTube video embeds in rich text field not saving

My guess is you're running into one of two issues. You're bumping into your php.ini file's max_intput_vars and/or post_max_size limitations. Your server has something like Suhosin or mod_security ...
Brad Bell's user avatar
  • 67.5k
4 votes
Accepted

How can I change the rich-text editor to remove the "Heading 1" option

formattingTags is not the correct syntax. You should be using formatting instead, as per my answer on this question.
Jamie Wade's user avatar
  • 3,644
4 votes
Accepted

Text Align Buttons for Rich Text Fields

Per their configuration docs, which also link to Craft's docs on the subject, it looks like you'd just need to add "alignment" to the plugins portion of one of your craft/config/redactor/ JSON config ...
Brad Bell's user avatar
  • 67.5k
4 votes

Font family choice in rich text

That depends on the RTE you're using and what kind of features it supports. With the default Redactor, it should be possible via the configs in craft/config/redactor/ folder. Peronally I don't think a ...
Bert Oost's user avatar
3 votes

Automatically link to entries in rich text field

How about just using the replace filter? {% set text = "A small boat surrounds a large ​island​​" %} {% set linkedText = text|replace({'boat':'<a href="/whatever">boat</a>'}) %} {{ ...
Jeremy Daalder's user avatar
3 votes
Accepted

How to customize HTML Purifier?

Like Brad says above, there's no way to configure the RichTextField's HTML Purifier instance – but you could easily create a custom fieldtype that instantiates HTML Purifier w/ different options. ...
Mats Mikkel Rummelhoff's user avatar
3 votes

How to customize HTML Purifier?

There's no way to configure the default Rich Text Field's use of HTMLPurifier, unfortunately, though it has been brought up before and is on our list to look at exposing to a config file post Craft 3 ...
Brad Bell's user avatar
  • 67.5k
3 votes

Emojis in Rich Text Field

It looks like Redactor has a plugin called “Clips” that allows you to: Create a dropdown of frequently used "snippets" of code, text, icons, emoji, you name it. Pixel and Tonic made it into a ...
Cavell Blood's user avatar
3 votes
Accepted

How to append / prepend into a rich text field

If you want to prepend another paragraph you could to this: {% set paragraphs = entry.body|split('</p>') %} {% for paragraph in paragraphs %} {% if loop.index == 1%} <p>Prepended ...
Marco Schuler's user avatar
3 votes
Accepted

Redactor can't add image into toolbar

You probably don't have an Asset Volume defined yet. The button won't show up if there are no Asset Volumes, regardless of what your Redactor config specifies. To add an Asset Volume, visit the ...
Brad Bell's user avatar
  • 67.5k
3 votes
Accepted

Check for an image in Rich Text Field

You could use the in operator to search for a substring in your markup. {% set imageExists = '<img' in entry.body.getRawContent() %} {% set classAttr = imageExists ? 'with-image' : '' %} <div ...
carlcs's user avatar
  • 36.3k
3 votes
Accepted

How to output a Rich Text Link to an Entry as a tooltip?

Not really a craft solution — but easiest might be jquery/ajax. Since you know the base URI, you can just create a selector for the route, and work from there. $("a[href*='route/to/definitions/']")....
Douglas McDonald's user avatar
3 votes
Accepted

How to add a button or format style in Craft 3 CKEditor (rich text field)

I asked the question on the Slack channel & got my answer. Thank you @kenyonkowal. The best way to customize your rich text editor is to use Redactor instead of CKeditor. You need to add a ...
mateostabio's user avatar
3 votes
Accepted

ckEditor and line breaks

Redactor uses newline \n for line breaks, resulting in needing to use the |nl2br filter to have them render as <br/> https://twig.symfony.com/doc/3.x/filters/nl2br.html CKEditor does not use \n ...
cherrykoda's user avatar
  • 1,114
2 votes

Is it possible to use Twig in a Rich Text Field?

I'm not sure when this changed, but Rich Text fields now appear to be parsed for reference tags (Craft 2.6)
Tim Kelty's user avatar
  • 3,081
2 votes

How do I prevent Redactor from wrapping <img> with <p />

I wrote a plugin called Retcon which uses DOMDocument to rewrite HTML content. Here's how you could unwrap your images using the retconUnwrap filter in a template: {{ entry.body|retconUnwrap('img') }...
Mats Mikkel Rummelhoff's user avatar
2 votes

Best method of text truncating

Wordsmith plugin is very useful in manipulating the text. For example: {{ entry.fieldHandle|chop(limit=100, unit='c', append=' ...') }}
Alex Ljamin's user avatar
2 votes
Accepted

Best method of text truncating

If you need to allow or disallow specific tags, you can use wordsmith plugin and its chop filter. But if you don't need such advanced functionality, you can just use Twig macros. In article ...
Piotr Pogorzelski's user avatar
2 votes

Smart quotes in rich text fields?

There's also another great plugin I came across recently called Typogrify. It also supports SmartyPants (as mentioned in another answer) along with several other nice typography improvements: Uses ...
Simon East's user avatar
2 votes

Rich-Text/Redactor hyperlink classes

I know this is a bit of an old question and has already been answered, but I took some of the solutions here a step further and wrote a plugin that lets you configure a list of class names that ...
stevecomrie's user avatar
2 votes

Limit text when output richtext

For my future self: This is my solution now in Craft CMS 3 and 4. {{ 'Hello world'|truncate(10) }} {# Output: Hello… #} An ellipsis (…) will be appended to the string if it needs to be truncated, by ...
mateostabio's user avatar
2 votes

Over ride auto-generated alt tag on image added via Rich Text field

The Retcon plugin works great for DOM manipulation. You can override the attribute with a default value or remove it completely. {{ entry.body|retconAttr('img', {'alt': entry.title}) }} {{ entry....
carlcs's user avatar
  • 36.3k
2 votes

Can you increase the max size of Rich Text fields?

Under your Rich Text field's setting, there is a "Column Type" option that's set to text by default, which will hold about 64k worth of data. You can change it to mediumtext, which will store about ...
Brad Bell's user avatar
  • 67.5k

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