I am new in magento. How can I add an html button on that location?
Asked
Active
Viewed 105 times
2 Answers
0
Do not know it has to be a button but you can add an hyperlink this way:
in app\code\vendor\module\etc\di.xml
<type name="Magento\Theme\Block\Html\Topmenu">
<plugin name="add_contact_us_menu" type="vendor\module\Plugin\TopMenu" sortOrder="1" />
</type>
in app\code\vendor\module\Plugin\TopMenu.php
<?php
namespace vendor\module\Plugin;
use Magento\Framework\Data\Tree\NodeFactory;
class TopMenu
{
protected $nodeFactory;
protected $_storeManager;
protected $_urlBuilder;
public function __construct(
NodeFactory $nodeFactory,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\UrlInterface $urlBuilder
) {
$this->nodeFactory = $nodeFactory;
$this->_storeManager = $storeManager;
$this->_urlBuilder = $urlBuilder;
}
public function beforeGetHtml(
\Magento\Theme\Block\Html\Topmenu $subject,
$outermostClass = '',
$childrenWrapClass = '',
$limit = 0
)
{
$node = $this->nodeFactory->create(
[
'data' => [
'name' => __('Node title'),
'id' => 'cutom-page',
'url' => your url here,
'has_active' => false,
'is_active' => false
],
'idField' => 'id',
'tree' => $subject->getMenu()->getTree(),
]
$subject->getMenu()->addChild($node);
}
}
Joao71
- 1,197
- 6
- 16
0
'data' => [
'name' => __('Contact Us'),
'id' => 'cutom-page',
'url' => 'http://magento244.local/what-is-new.html',
'has_active' => false,
'is_active' => false
],
'idField' => 'id',
'tree' => $subject->getMenu()->getTree(),
]);
$subject->getMenu()->addChild($node);
Thank you @Joao71 This code is working but you missed );
Bhaktahari Palai
- 1
- 3
