I'm trying to html encode a string that will be used as a tooltip in a google map.
$cs = Yii::app()->getClientScript();
$cs->registerScript('someID', <<<EOD
function mapsetup() {
//...
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
// works:
title: '$model->name'
// doesn't work:
title: '{${CHtml::encode($model->name)}}'
});
// ...
}
mapsetup();
EOD
, CClientScript::POS_LOAD
);
If I use the line title: '$model->name'
, it results in the following expansion:
title: 'Some Name'
If I instead use the line title: '{${CHtml::encode($model->name)}}'
, it results in the following expansion:
title: ''
CHtml::encode
works elsewhere on the same page fine, but it doesn't seem to work in the php heredoc.
- Do I even need to html encode javascript string data that will be rendered to the browser?
- How can I get CHtml::encode to work in the heredoc?