Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apostrophe converted into & # 039 ; in twig

This question has been asked before here:

Question

But it doesn't solve my problem.

After I got data from database with apostrophe, I'm putting it inside a text input using

c_name='{{company_name}}';
$("#company_name").val(c_name);

It's giving result like

some Hatchery & Shrimp & #039;s Culture ltd.

So I applied the solution of that question like

c_name='{{company_name|raw}}';
$("#company_name").val(c_name);

It's giving me an error like

SyntaxError: missing ; before statement 
c_name='some Hatchery & Shrimp's Culture ltd.';

Showing error just after the Shrimp' and before s. Obviously string ended before it actually ends and expecting a ;

So I tried again with

c_name={{company_name|raw}};

SyntaxError: missing ; before statement
c_name=some Hatchery & Shrimp's Culture ltd.;

Now it's showing error just after the first white space,in this case before 'H'

My question is how can I handle apostrophe in twig? '|raw' is causing problem for me.

like image 927
AtanuCSE Avatar asked Feb 09 '14 04:02

AtanuCSE


People also ask

What are the 3 apostrophes?

The apostrophe has three uses: 1) to form possessive nouns; 2) to show the omission of letters; and 3) to indicate plurals of letters, numbers, and symbols. ​Do not ​use apostrophes to form possessive ​pronouns ​(i.e. ​his​/​her ​computer) or ​noun ​plurals that are not possessives.

What symbol is apostrophe?

What is an Apostrophe? An apostrophe is a punctuation mark (') that appears as part of a word to show possession, to make a plural number or to indicate the omission of one or more letters.


1 Answers

c_name = '{{ company_name|e('js')|raw }}';

Since you're in a Javascript context, you need to escape for Javascript (and then add raw to avoid additional automatic escaping for HTML).

like image 89
deceze Avatar answered Sep 21 '22 13:09

deceze