<p>You shouldn't need any <code>convert_encoding</code> here. From your results, the special characters are coming out fine, it's your <code>&amp;nbsp</code> that is your problem. </p>

<p>For this to go you can use the <code>|raw</code> Twig filter.</p>

CC BY-SA 4.0
2019-03-07T17:54:13.867Z
Hi and thanks. Sorry for the delay, had to pivot to another project. I did try {{ item.articleBodySpanish.type('bodyText')[0].bodyText|striptags|raw|slice(0, 200)|default('Lee mas') }} but it still gives me the version with good special characters but uninterpreted &nbsp; ... what am I missing? Thanks again.
Sapphireblue
CC BY-SA 4.0
2019-03-08T07:38:26.777Z
ahh, I didn't actually realize that |raw had to be the last filter. that did it.
Sapphireblue
CC BY-SA 4.0
2019-03-03T19:16:03.117Z
2019-03-03T19:16:03.117Z
Oli
<p>Standard "when article has no summary, output the first 200 characters of the body minus HTML" logic going on here. We're implementing some Spanish-language features for the first time and, while special characters are stored fine in the database (utf_unicode_ci collation) and they output fine on the front end when convert_encoding isn't applied, they come out garbled when convert_encoding is applied.</p>

<p>My code is:</p>

<pre><code>{{ item.articleBodySpanish.type('bodyText')[0].bodyText|striptags|convert_encoding('UTF-8', 'HTML-ENTITIES')|slice(0, 200)|default('Lee mas') }}...
</code></pre>

<p>I have an entry where the database contains this for articleBodySpanish: </p>

<pre><code>&lt;p&gt;Empuja sus puños contra los postes y sigue insistiendo en que ve a los fantasmas.&amp;nbsp;Empuja sus puños contra los postes y sigue insistiendo en que ve a los fantasmas.&lt;/p&gt;
</code></pre>

<p>With the code above, the output I get is as follows:</p>

<pre><code>Empuja sus puÃ±os contra los postes y sigue insistiendo en que ve a los fantasmas. Empuja sus puÃ±os contra los postes y sigue insistiendo en que ve a los fantasmas.
</code></pre>

<p>If I remove the <strong>|convert_encoding('UTF-8', 'HTML-ENTITIES')</strong> the output becomes this, so I can't even just take it out to moot the issue:</p>

<pre><code>Empuja sus puños contra los postes y sigue insistiendo en que ve a los fantasmas.&amp;nbsp;Empuja sus puños contra los postes y sigue insistiendo en que ve a los fantasmas.
</code></pre>

<p>What can I do here?</p>

<templating>
convert_encoding is screwing up Spanish-language characters
# convert_encoding is screwing up Spanish-language characters

(Asked by: username_0 on 2019-03-03)

Standard "when article has no summary, output the first 200 characters of the body minus HTML" logic going on here. We're implementing some Spanish-language features for the first time and, while special characters are stored fine in the database (utf_unicode_ci collation) and they output fine on the front end when convert_encoding isn't applied, they come out garbled when convert_encoding is applied.
My code is:
{{ item.articleBodySpanish.type('bodyText')[0].bodyText|striptags|convert_encoding('UTF-8', 'HTML-ENTITIES')|slice(0, 200)|default('Lee mas') }}...

I have an entry where the database contains this for articleBodySpanish: 
Empuja sus puños contra los postes y sigue insistiendo en que ve a los fantasmas. Empuja sus puños contra los postes y sigue insistiendo en que ve a los fantasmas.

With the code above, the output I get is as follows:
Empuja sus puÃ±os contra los postes y sigue insistiendo en que ve a los fantasmas. Empuja sus puÃ±os contra los postes y sigue insistiendo en que ve a los fantasmas.

If I remove the |convert_encoding('UTF-8', 'HTML-ENTITIES') the output becomes this, so I can't even just take it out to moot the issue:
Empuja sus puños contra los postes y sigue insistiendo en que ve a los fantasmas. Empuja sus puños contra los postes y sigue insistiendo en que ve a los fantasmas.

What can I do here?

**Tags:** templating

---

## 1 answers

### Answer by username_1 on 2019-03-03. Score: 1 | Accepted answer

You shouldn't need any `convert_encoding` here. From your results, the special characters are coming out fine, it's your  that is your problem.

For this to go you can use the `|raw` Twig filter.

> **Comments:**
> **username_0**: Hi and thanks. Sorry for the delay, had to pivot to another project. I did try {{ item.articleBodySpanish.type('bodyText')[0].bodyText|striptags|raw|slice(0, 200)|default('Lee mas') }} but it still gives me the version with good special characters but uninterpreted &nbsp; ... what am I missing? Thanks again.  
> **username_0**: ahh, I didn't actually realize that |raw had to be the last filter. that did it.  

---

