This is a migrated thread and some comments may be shown as answers.

Stupid Question Time

3 Answers 30 Views
Menu
This is a migrated thread and some comments may be shown as answers.
DavidOBrien
Top achievements
Rank 2
DavidOBrien asked on 01 Apr 2013, 02:37 PM
$menu = new \Kendo\UI\Menu('menu');
$menu->addItem(
    new \Kendo\UI\MenuItem('Home')
    ,new \Kendo\UI\MenuItem('Blog')
    ,new \Kendo\UI\MenuItem('Documentation')
    ,new \Kendo\UI\MenuItem('Code Changes')
    ,new \Kendo\UI\MenuItem('Community')
    ,new \Kendo\UI\MenuItem('Pricing')
    ,new \Kendo\UI\MenuItem('Downloads')
    ,new \Kendo\UI\MenuItem('About Us')
);
How do I specify the url to open if that item is selected?
It seems it should be easier than having to add a content("<a href="link.php">Home</a>") to each item shouldn't it?

3 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 03 Apr 2013, 01:09 PM
Hi David,

Generally speaking, you should be able to specify the url of the MenuItem through its url method.
<?php
$item = new \Kendo\UI\MenuItem();
$item->text('Google');
$item->url('http://www.google.com');
?>

I am afraid that currently the method is not available - we will log this as a bug and will do our best to provide a fix as soon as possible. As a small sign of our appreciation for this discovery I updated your Telerik points.

Meanwhile, as a workaround please set the link as content:
<?php>
$item = new \Kendo\UI\MenuItem('<a href="http://www.google.com">Google</a>');
?>


Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Oscar
Top achievements
Rank 2
answered on 18 Apr 2013, 07:24 PM
This will show the html as literal text.

What I've done as a workaround is change the renderContent function in UI/MenuItem.php. This way you will be able to use the url function on the item.
protected function renderContent($element) {
    $content = $this->getProperty('content');
            $url = $this->getProperty('url');
 
    if ($content) {
        $subgroup = new \Kendo\Html\Element('ul');
        $subitem = new \Kendo\Html\Element('li');
        $anchor = new \Kendo\Html\Element('a');
                 
        if ($url) {
                        $anchor->attr('href', $url);
                        $anchor->html($content);
                        $subitem->append($anchor);
                    } else {
                        $subitem->html($content);
                    }
 
        $subgroup->append($subitem);
        $element->append($subgroup);
    }
}
Though I'm waiting for the feature to become available as well so the item is selected by default if the browsing URL matches the URL provided in the url function. Can't seem to find a simple workaround for that as this also needs an altering in the kendo javascript code.
0
Alexander Valchev
Telerik team
answered on 22 Apr 2013, 08:41 AM
Hello David,

Thank you for the feedback.
I am glad to inform you that this bug is fixed in the latest internal build. Please download it and give it a try. The syntax for creating the menu item is:
$foo = new \Kendo\UI\MenuItem();
$foo->text('foo');
$foo->url('http://www.google.com');


Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Menu
Asked by
DavidOBrien
Top achievements
Rank 2
Answers by
Alexander Valchev
Telerik team
Oscar
Top achievements
Rank 2
Share this question
or