Afdding HTML elements to zend navigation

2019-09-07 04:55发布

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?

2条回答
乱世女痞
2楼-- · 2019-09-07 05:37

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

查看更多
3楼-- · 2019-09-07 05:47

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.

查看更多
登录 后发表回答