On a Symfony web app I’m building, all my HTML page titles have an ampersand in them. However, Symfony is escaping the ampersand, and my title ends up looking like this:
<title>Home - Wallace &amp;amp; Gromit., Inc.</title>
My view YAML defines the title with an unescaped ampersand:
default:
...
metas:
...
title: Wallace & Gromit., Inc.
And I’ve tried all sorts of escaping strategies with the include_title() function in my layout.php, but nothing seems to work.
<head>
<?php include_http_metas() ?>
<?php if (has_slot('title_prefix')): ?>
<?php $sf_context->getResponse()->setTitle(get_slot('title_prefix') . ' - ' . $sf_context->getResponse()->getTitle(ESC_SPECIALCHARS)) ?>
<?php endif; ?>
<?php include_metas() ?>
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
<?php include_stylesheets() ?>
<!--[if IE 7]><link rel="stylesheet" type="text/css" href="css/screen_ie.css" /><![endif]-->
<?php include_javascripts() ?>
<?php include_title(ESC_SPECIALCHARS) ?>
</head>
Any ideas?
The setTitle() method has a default parameter for escaping the title. It looks like this:
You shouldn’t be escaping the the call to getTitle() if you are using the default parameter to setTitle(). Try using ESC_RAW instead of ESC_SPECIALCHARS.