Reputation: 577
What I need
I need to show special symbols in view page.
say name: Sara Fernström oksss.
php code
{% set name=value.metadata.name %}
<h3>
{%if name|length < 40 %}
{% set strategy = 'html' %}
{% autoescape 'html' %}
{{name|escape(strategy)|raw}}
{% endautoescape %}
refrence
output :
Sara Fernstru00f6m
but o/p should be:
Sara Fernström oksss
Upvotes: 3
Views: 3248
Reputation: 39380
Check how you store the data in your database with the charset and collate params as example:
namespace Acme\DemoBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="MyEntityRepository")
* @ORM\Table(name="my_entity",
* options={"collate"="utf8mb4_unicode_ci", "charset"="utf8mb4"})})
*/
class MyEntity
{
....
Hope this help
Upvotes: 0
Reputation: 493
Your issue is not with Twig, your issue is with your page and string encoding.
Make sure the string is UTF-8 before it is passed to Twig. Make sure the document is UTF-8.
Then use
{{ data }}
to output your string.
I work with åöä all the time(swedish) and literally never had to use anything else.
Upvotes: 1
Reputation: 4835
You will need to decode the string in the proper charset:
{{ data|convert_encoding('UTF-8', 'YourCharset') }}
data will be your string, the first value is the output-charset the second the input-charset, you can also see the twig doc for this: http://twig.sensiolabs.org/doc/filters/convert_encoding.html
If the this doesn't work maybe try to decode the variable inside your php code
:
For your code it would be something like this I think:
value.metadata.setName(utf8_decode(value.metadata.getName());
Upvotes: 0