Is it possible to render absolute urls with the knp menu?

562 views
Skip to first unread message

Bruno Reis

unread,
Aug 15, 2014, 3:29:33 PM8/15/14
to symfony-...@googlegroups.com
Hi all, 

Is it possible to render absolute urls with the knp menu? Is the menu aware of the complete path, including the domain info? 

* I found just one issue on stackoverflow with a broken link and tried the "routeAbsolute' parameter (as told there) but it did not work. 

David Buchmann

unread,
Aug 16, 2014, 7:11:24 AM8/16/14
to symfony-...@googlegroups.com
hi bruno,

knp menu items have uri, they know nothing about symfony, routes or
anything:
https://github.com/KnpLabs/KnpMenu/blob/master/src/Knp/Menu/ItemInterface.php#L46

the menu factory is responsible for converting menu nodes to menu items.
looking at this code in the cmf menu factory, it looks like you are on
the right trail:
https://github.com/symfony-cmf/MenuBundle/blob/master/ContentAwareFactory.php#L228-L264

the menu node can have an option 'routeAbsolute' and if you set that to
true, you should get absolute urls.

if this does really not work, there would be a bug somewhere - to debug
you could check if routeAbsolute really is true, or if hardcoding true
in the ContentAwareFactory helps...

cheers,david
> --
> You received this message because you are subscribed to the Google
> Groups "symfony-cmf-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to symfony-cmf-us...@googlegroups.com
> <mailto:symfony-cmf-us...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

--
Liip AG // Agile Web Development // T +41 26 422 25 11
CH-1700 Fribourg // PGP 0xA581808B // www.liip.ch

Bruno Reis

unread,
Aug 19, 2014, 4:06:09 PM8/19/14
to symfony-...@googlegroups.com
it seems that the factory is run before the twig extension, so it's not possible to add routeAbsolute to the proccess of converting nodes into items. 

If I do something like...

{{ knp_menu_render('simple/main', {'currentClass': 'pure-menu-selected', 'depth': 2, 'routeAbsolute':true, 'linkType':'urf'}) }}

...nothing happens. 

But If I intercept the CreateMenuItemFromNodeEvent event and force the it, it shows that routeAbsolute is working:

        $node = $event->getNode();
        $factory = $event->getFactory();
        $options = $node->getOptions();
        $options['routeAbsolute'] = true;
        $item = $factory->createItem($node->getName(),$options);
        $event->setItem($item);

But, I think the first option should also work. And it's sure a cleaner way to do it. 



To unsubscribe from this group and stop receiving emails from it, send an email to symfony-cmf-us...@googlegroups.com.

David Buchmann

unread,
Aug 30, 2014, 11:16:54 AM8/30/14
to symfony-...@googlegroups.com
> it seems that the factory is run before the twig extension, so it's not
> possible to add routeAbsolute to the proccess of converting nodes into
> items.
>
> If I do something like...
>
> {{ knp_menu_render('simple/main', {'currentClass': 'pure-menu-selected',
> 'depth': 2, 'routeAbsolute':true, 'linkType':'urf'}) }}
>
> ...nothing happens.

but the other options are passed through? i agree that it should be
possible to overwrite these options here, whithout some event listener.
Reply all
Reply to author
Forward
0 new messages