Afdding HTML elements to zend navigation

徘徊边缘 提交于 2020-01-06 07:25:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!