HTML Formatting not working in symfony 2 - symfony

I have a symfony 2 form in back-end where I have rich text field with tiny mce editor. The data type of this field is varchar in database table.
When I prints its content on front side then formatting does not work. It shows plain text rather than html formatted content.
How it prints:
< p >< strong >Hello< /strong >< /p >
How it should print:
Hello
Any solution?

To print a variable which contains HTML characters, as code string use escape (which is default in Symfony)
{{ content|escape }}
To print a variable which contains HTML characters, as a none code string use raw
{{ content|raw }}

Related

How to render variable without special characters

We are using a variable like this, to render the text without special characters like HELP & SUPPORT,
{{ variable|render|striptags|trim|convert_encoding('UTF-8',
'HTML-ENTITIES') }}
After upgrading from Drupal 8 to 9, we are getting errors like,
Notice: iconv(): Wrong charset, conversion from HTML-ENTITIES' to UTF-8' is not allowed in twig_convert_encoding() (line 1009 of
/var/www/html/stg.flowbusiness.co/vendor/twig/twig/src/Extension/CoreExtension.php)
And the variable is not displaying with convert_encoding function.
So, any suggestions to display the text without special characters in drupal 9.
convert_encoding() in twig is function meant to convert a string from one encoding to another; HTML-ENTITIES is not an encoding; this why the error is raised.
https://twig.symfony.com/doc/2.x/filters/convert_encoding.html
As it's not doing what you're using it for, you should remove that part.
If you want to have the html entities to be rendered correctly, you should remove the striptags part too.
Using |raw filter would normally render chars as you need.
This twig rendering tag
{{ variable|render|striptags|trim|convert_encoding('UTF-8', 'HTML-ENTITIES') }}
would become
{{ variable|raw }}
While & char is an HTML entity, it would be correctly render as raw, without showing special chars.

Escaping multiline wordpress shortcodes

How to escape multiline wordpress shortcode?
[accordion_item title="Item 2"]
item content
[/accordion_item]
We could use double brakets, but "/" sign brokes everything. Can't belive WP guys lost this case (
[[accordion_item title="Item 3"]]
item content
[[accordion_item]]
this works, but code below doesn't escaped properly
[[accordion_item title="Item 3"]]
item content
[[/accordion_item]]
Don't want to replace manually brakets with html codes. (and WP automatically get them back after user switch editor mode to visual)
Thanks in advance.
Function get_shortcode_regex() in shortcodes.php makes all logic with escaping shortcodes parsing (capture group 1 and 5)
For example with
[[new_something my_attr="test"]And have content!! [vc_tabs][/vc_tabs][/new_something]]
After preg_match_all you will get that
first capture group is not empty and it is "[" (so you can know that this shortcode is not for rendering)
second capture group will show shortcode name "new_something"
third capture group will show everything in attributes " my_attr="test""
four capture group will show content And have content!! [vc_tabs][/vc_tabs]
Five capture group will show that escape characters has at end.
Basically this means that all information is known when you write escape like this: [[your_shortcode]content[/your_shortcode]]
the Answer: replacing [ by [ and ] by ]
Link: https://wordpress.stackexchange.com/questions/33960/how-do-i-escape-a-in-a-short-code
Side Note:
Wysiwyg <=> text transition causing html encoding is, and always be a problem. I would recommend just getting rig of the visual editor all together!

Wrong quotes handling in JMS Translation bundle

Faced strange quote escaping in JMS Translation bundle (or I'm doing something wrong). The target text in xliff file is like "quoted-text". On result web page it is shown like "quoted-text" because ampersand in html code is printed like & instead of 'as is' - &. Seems like there is excess symbol escaping somewhere between xliff reading and html code generation. Could anybody suggest how to solve this problem?
Solved by adding raw filter to translated string in twig file, like:
{{ 'quoted.text' | trans | desc('text which translation has quotes') | raw }}

Why does MVC double-encode unobtrusive validation attributes?

For example:
data-val-equalto="&#39;MyProperty5&#39; and &#39;MyProperty4&#39; do not match."
Question: Why is the & character encoded again into & (&#39;), instead of just outputting the character reference as is (') ?
The jquery.validate plugin seems to be parsing &#39; as '.
The problem doesn't seem to be in Razor, but with the code that generates the unobtrusive validation attributes, the following code:
<span title="#("'MyProperty5' and 'MyProperty4' do not match.")"></span>
... outputs correctly:
<span title="'MyProperty5' and 'MyProperty4' do not match."></span>
Found out that the problem is in ASP.NET MVC, there's a method called GetValidationAttributes that adds HTML-encoded values to a dictionary, and then the values are encoded again by TagBuilder. It would be good to know why they are doing this.
Try outputting using the Html.Raw method.
Otherwise, Razor does not assume you are trying to output encoded HTML and encodes it again.
Given
string text = `Bread & Breakfast`;
#text will be output as Bread &amp; Breakfast because the & is HTML Encoded
#Html.Raw(text) will be output as "Bread & Breakfast"
UPDATE based on your update
I can't tell you why jQuery Validate works that way, but there's an old adage "if it hurts when you do X, stop doing X".
You don't really need to encode the single quote in your output HTML. Both of the following produce the same result:
<span title="'MyProperty5' and 'MyProperty4' do not match.">
Span With Encoded Title
</span>
<br />
<span title="'MyProperty5' and 'MyProperty4' do not match.">
Span With non-Encoded Title
</span>
This issue was fixed on MVC v4.

Extended use of replace filter in twig?

i checked out the documentation for the replace filter in twig. my problem is that, suppose i have a variable say contvariable, and the content passed through that variable from the controller is dynamic
return $this->render('RodasysFormstudyBundle:Default:addclientname.html.twig', array('contvariable' =>$sometext));
this $sometext variable will contain texts like
$sometext='%Sun% rises in the East';
the text inside the %% should be displayed as an input field in the browser. I did not find any examples in the web like to replace the content inside the %% (what ever the content be whether its sun or the moon). Is this possible to do this using replace filter or should i follow some other method such as to replace the content in controller before sending it to twig..
please help..
You could do something like that (with the 'raw' filter) :
{{ "%foo% rises in the East"|replace({'%foo%': "<input type='text' name='"~foo~"' value='"~foo~"'/>"})|raw }}
foo is a variable sent by your controller, with the value of your choice.

Resources