问题
So I wrote a class as such:
class Users_Navigation_Page_Notification extends Zend_Navigation_Page_Mvc{
public function setLabel($label){
if(substr($label, 0 , 1) == ':'){
$label = 'Notification';
}
return parent::setLabel($label);
}
}
And if I try something like:
$label = 'Notification' . '<span>test</span>';
It echo's out Notificationtest
which it shouldn't.
How do I make it render HTML elements out?
回答1:
When rendering navigations, the view helper is hardcoded to escape the label of each navigation page which by default uses htmlspecialchars. This would effectively disable HTML since the tags are replaced with HTML entities.
You can try to cheat a bit and change the escaping mechanism prior to outputting your navigation:
$view->setEscape('trim'); // will allow html and remove escaping
echo $view->navigation()->menu(); // output navigation
$view->setEscape('htmlspecialchars'); // restore escaping mechanism
In the above code, you can change $view to $this if you are within a view script.
回答2:
Answer here https://stackoverflow.com/a/32823280/3684315 suggests using escapeLabels(false) function to disable escaping, which seems like a nicer solution.
<?= $this->navigation()->menu()->escapeLabels(false) ?>
来源:https://stackoverflow.com/questions/12730760/afdding-html-elements-to-zend-navigation