0

I'm trying to add non category links to the top nav using the following code. It displays "Test page" & "Test page3" but not "Test page2". So I'm assuming that there is something wrong with the code as it display the first and last. Any ideas?

<?php
namespace atharna\navUpdate\Observer;
use Magento\Framework\Event\Observer as EventObserver;
use Magento\Framework\Data\Tree\Node;
use Magento\Framework\Event\ObserverInterface;
class Topmenu implements ObserverInterface
 {

/**
 * @param EventObserver $observer
 * @return $this
 */
public function execute(EventObserver $observer)
{
   /** @var \Magento\Framework\Data\Tree\Node $menu */
   $menu = $observer->getMenu();
   $tree = $menu->getTree();
   $data = [
       'name'      => __('Test page'),
       'id'        => 'test-page',
       'url'       => 'test-page',
   ];
   $node = new Node($data, 'id', $tree, $menu);
   $menu->addChild($node);
   $data = [
       'name'      => __('Test page2'),
       'id'        => 'test-page2',
       'url'       => 'test-page2',
   ];
   $node = new Node($data, 'id2', $tree, $menu);
   $menu->addChild($node);
   $data = [
        'name'      => __('Test page3'),
        'id'        => 'test-page3',
        'url'       => 'test-page3',
   ];
   $node = new Node($data, 'id3', $tree, $menu);
   $menu->addChild($node);
   return $this;
}

}

?>
5
  • What if you move the part of the code that adds the "TEst page 2" after the code that adds "Test page 3" ? Commented May 26, 2016 at 13:39
  • I now see "Test page2" and not "Test page3"
    – Mark
    Commented May 26, 2016 at 13:43
  • That means that's not a bug with the code. It sounds like a CSS bug. Please inspect the source code using firebug or Chrome developer tools and see if the menu link is here but just hidden Commented May 26, 2016 at 13:44
  • Only 2 of the three links are displaying in the source code. No hidden elements are there
    – Mark
    Commented May 26, 2016 at 13:47
  • When you say move the add bit which parts should I be moving?
    – Mark
    Commented May 26, 2016 at 13:52

1 Answer 1

1

Found the solution to the problem.

They all need to have the same 'id' within the new node()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.