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.
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 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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With