3

Before you think this has already been answered, yes it is but I can't manage to get that fix working so I'm looking for another one.

I have a "title" field in a couple of my matrix blocks but my client want's to add a Bold word every now and then. Now I tried that with a rich text field which works fine except that it keeps adding a <p> tag to my text which makes the Indexing go wrong etc plus it shouldn't be so hard to remove but apparently it is...

This is my custom json at the moment:

{
    buttons: ['bold', 'italic'],
    maxHeight: 50,
    paragraphize: false,
    replaceDivs: false,
    linebreaks: true,
    enterKey: false
}

In every fix I find here this should do it but somehow it wont..

  • 2
    Can you link to the similar solutions which you have already tried? – Lindsey D Oct 17 '16 at 18:22
5

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 linebreaks, you might want to add the nl2br filter as well:

<h1>{{ entry.titleField|striptags('<strong><em><br>')|raw|nl2br }}</h1>
  • Didn't know this was a thing. To add something on it. Use |raw behind the 'striptags()' Function if you also include <a> tags or else they show the entire tag. Atleast on my end. – Justin Dekkers Oct 19 '16 at 12:44
  • You're absolutely right, @JustinDekkers – I'll add the |raw filter to my answer. Thanks! – Mats Mikkel Rummelhoff Oct 19 '16 at 12:45
1

Another option would be to use Parsedown to add formatting:

{{entry.titleField|pd('line')}}

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.