Symfony - Is it possible to disable output escaping per module (or per template)?

10,089

Solution 1

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.

Solution 2

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

sfOutputEscaperGetterDecorator::unescape($html)

Solution 3

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).

Share:
10,089
Steven Mercatante
Author by

Steven Mercatante

Big fan of Python, JavaScript, Elixir and functional programming.

Updated on June 04, 2022

Comments

  • Steven Mercatante
    Steven Mercatante almost 2 years

    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?