7

I'm trying to output some HTML in an XML template and Symfony's escaping method is messing it up. So I tried making a copy of settings.yml in the module's config folder, but it seems to be completely ignored. Is there an easy way to change the escaping_strategy and/or escaping_method settings per module or even per template?

Steven Mercatante
  • 24,757
  • 9
  • 65
  • 109

3 Answers3

17

While output escaping is turned on you still have access to the raw value through $sf_data. For example, if the HTML you're trying to output was stored in a variable called html in your action:

$this->html = '<b>My HTML</b>';

You could get the unescaped value with this:

<?php echo $sf_data->getRaw('html') ?>

http://www.symfony-project.org/book/1_0/07-Inside-the-View-Layer#chapter_07_sub_activating_output_escaping

I don't believe there is a way to disable this functionality on a per-module basis.

nortron
  • 3,873
  • 1
  • 24
  • 27
  • 5
    Looks cool, didn't know about this. I didn't understand the question like this and was about to answer, just for an object : $yourObject->getRawValue()->getProperty() .. if it helps... – Julien Feb 01 '10 at 22:59
  • Julien: if he's trying to work out of a model object your solution would be perfect, you should post as an answer just in case. – nortron Feb 01 '10 at 23:00
  • Thanks Cryo, $sf_data->getRaw() did the trick. Julien, thanks for the info on how to use this from the model. – Steven Mercatante Feb 02 '10 at 01:03
11

getRaw only works if the variable is passed from the action. for variable within view use

sfOutputEscaperGetterDecorator::unescape($html)
Hesky
  • 781
  • 7
  • 5
  • I was looking to unescape some attribute, but unfortunately, attributes are not accessibles through $sf_data->getRaw(..). But your answer did the trick! Thanks! – Jonathan Pasquier Apr 01 '16 at 10:47
9

Just run into this problem today and i manage to solve it by setting sfConfig::set('sf_escaping_strategy', false) in my controller (either in preExecute method for all the actions in that module or in a specific action - executeWhatever).

Vlad Jula-Nedelcu
  • 1,681
  • 11
  • 17