Discussion:
Knp Menu Bundle - passing options from a twig template to the menu builder
Darren Black
2012-07-30 02:35:38 UTC
Permalink
I would like to add an 'id' attribute to a menu's <ul> tag, which i can do
easily from the builder method, using setChildrenAttribute:

public function mainMenu(FactoryInterface $factory, array $options)
{
$menu = $factory->createItem('root');

$menu->addChild('Telephone Directory', array('route' => 'home'));
$menu->setChildrenAttribute('id', 'main_menu');
return $menu;
}

But, i would like set the id for the menu in the template. There appears a
way to pass options from the template to the builder, in the 2nd parameter
in knp_menu_render:

{{ knp_menu_render('AcmeSomeBundle:Builder:mainMenu', {'id':
'main_menu'}) }}

But, the options set here don't make it to the mainMenu builder method -
$options comes in as an empty array. What am I doing wrong - how can i
populate the options parameter in the builders mainMenu method?

thanks
db
--
If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "Symfony2" group.
To post to this group, send email to symfony2-/***@public.gmane.org
To unsubscribe from this group, send email to
symfony2+unsubscribe-/***@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/symfony2?hl=en
Darren Black
2012-07-30 03:04:02 UTC
Permalink
I'll answer my own question - this:

{{ knp_menu_render('AcmeSomeBundle:Builder:mainMenu', {'id':
'main_menu'}) }}

passes arguments to the renderer, not the builder. I can pass options to
the builder using - knp_menu_get:

{% set main_menu = knp_menu_get( 'AcmeSomeBundle:Builder:mainMenu' ,
[], {'id': 'main_menu'}) %}

and render then it with:

{{ knp_menu_render(main_menu) }}

db
Post by Darren Black
I would like to add an 'id' attribute to a menu's <ul> tag, which i can do
public function mainMenu(FactoryInterface $factory, array $options)
{
$menu = $factory->createItem('root');
$menu->addChild('Telephone Directory', array('route' => 'home'));
$menu->setChildrenAttribute('id', 'main_menu');
return $menu;
}
But, i would like set the id for the menu in the template. There appears a
way to pass options from the template to the builder, in the 2nd parameter
'main_menu'}) }}
But, the options set here don't make it to the mainMenu builder method -
$options comes in as an empty array. What am I doing wrong - how can i
populate the options parameter in the builders mainMenu method?
thanks
db
--
If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "Symfony2" group.
To post to this group, send email to symfony2-/***@public.gmane.org
To unsubscribe from this group, send email to
symfony2+unsubscribe-/***@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/symfony2?hl=en
Leevi Graham
2013-01-17 07:02:42 UTC
Permalink
I think this may have been a bug. I've submitted a pull request
here: https://github.com/KnpLabs/KnpMenu/pull/90
Post by Darren Black
'main_menu'}) }}
passes arguments to the renderer, not the builder. I can pass options to
{% set main_menu = knp_menu_get( 'AcmeSomeBundle:Builder:mainMenu' ,
[], {'id': 'main_menu'}) %}
{{ knp_menu_render(main_menu) }}
db
Post by Darren Black
I would like to add an 'id' attribute to a menu's <ul> tag, which i can
public function mainMenu(FactoryInterface $factory, array $options)
{
$menu = $factory->createItem('root');
$menu->addChild('Telephone Directory', array('route' => 'home'));
$menu->setChildrenAttribute('id', 'main_menu');
return $menu;
}
But, i would like set the id for the menu in the template. There appears
a way to pass options from the template to the builder, in the 2nd
'main_menu'}) }}
But, the options set here don't make it to the mainMenu builder method -
$options comes in as an empty array. What am I doing wrong - how can i
populate the options parameter in the builders mainMenu method?
thanks
db
--
--
If you want to report a vulnerability issue on Symfony, please read the procedure on http://symfony.com/security

You received this message because you are subscribed to the Google
Groups "Symfony2" group.
To post to this group, send email to symfony2-/***@public.gmane.org
To unsubscribe from this group, send email to
symfony2+unsubscribe-/***@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/symfony2?hl=en
Loading...