how to allow knpmenu label cotains raw html

Example:
In menu builder:
 $menu->addChild($trans->trans('week.'.$weekday)."
$showDate"."($count)",
           array(
             'route' => 'prospection_list_appointement',
             'routeParameters' => array('date' => $i),
             'attributes' => array('class' => $childClass),
             'extras' => array('safe_label' =>true),                     
             ));       
in the twig template:
{{ knp_menu_render('AddepiProspectionBundle:Builder:dateMenu',{'allow_safe_labels': true})|raw }}
the hint is ,you need to set allow_safe_labels to true, and allow twig the generate raw content, and also, you need set the child element with extra=>safe_label to be true. Cause this is really unsuggested to do so, a XSS whole will be created if this menu can be modified by any user.
Or there is another way to do it is just override the default twig template. for example:
https://github.com/KnpLabs/KnpMenuBundle/blob/master/Resources/doc/i18n.md
this is an example to override and add il8n, we can do the same thing to render the label:


{% extends 'knp_menu.html.twig' %}
{% block label %}{{ item.label|raw }}{% endblock %}

and then we can try to use it by :
{{ knp_menu_render('name_of_your_menu', {'template': 'AcmeMainBundle:Default:knp_menu.html.twig'}) }}
if our personalized template's name is AcmeMainBundle:Default:knp_menu.html.twig
So by this way we can directly let it be raw without any configuration, but this is really not recommend.

评论

热门帖子