<p>Raw doesn't close tags tags for you, it just allows them to be processed rather than printed only. </p>

<p>The only reason you are seeing closing tags I'm guessing is because your inspector (chrome/safari) is adding them in. Do "view source" to see the real output.</p>

<p>Your problem here is just rogue open tags</p>

CC BY-SA 3.0
2015-11-17T11:18:35.883Z
2015-11-17T11:18:35.883Z
Oli
<p>I got a rich text field.<br>
I made an excerpt with <code>striptags</code> <code>slice</code> and <code>raw</code> twig functions.<br>
It works fine most of the time (<code>raw</code> close tags when <code>slice</code> cuts inside a <code>&lt;p&gt;</code>).  </p>

<pre><code>&lt;div&gt;{{ textBlock.text | striptags("&lt;p&gt;&lt;br&gt;&lt;div&gt;&lt;li&gt;&lt;em&gt;") | slice(0, 275) | raw }}...&lt;/div&gt;
</code></pre>

<p>But sometimes it completely breaks and put plenty of empty tags anywhere :</p>

<p><a href="https://i.sstatic.net/bbdRZ.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/bbdRZ.jpg" alt="enter image description here"></a></p>

<p>I noticed that it happened when the original text is cut in the middle of double tags like :<br>
<code>&lt;p&gt;&lt;em&gt;Some text cut by slice function here&lt;/em&gt;&lt;/p&gt;</code></p>

<p>Real bug no ?</p>

<templating><twigextension>
Craft rich text field excerpt with slice and raw breaks when cut inside double tags
# Craft rich text field excerpt with slice and raw breaks when cut inside double tags

(Asked by: username_0 on 2015-11-17)

I got a rich text field.
I made an excerpt with striptags slice and raw twig functions.
It works fine most of the time (raw close tags when slice cuts inside a ).  
{{ textBlock.text | striptags("") | slice(0, 275) | raw }}...

But sometimes it completely breaks and put plenty of empty tags anywhere :

I noticed that it happened when the original text is cut in the middle of double tags like :
Some text cut by slice function here
Real bug no ?

**Tags:** templating, twigextension

---

## 1 answers

### Answer by username_1 on 2015-11-17. Score: 2

Raw doesn't close tags tags for you, it just allows them to be processed rather than printed only.

The only reason you are seeing closing tags I'm guessing is because your inspector (chrome/safari) is adding them in. Do "view source" to see the real output.

Your problem here is just rogue open tags


---

