For first create block PHP under Vendor/Module/Block1
Code should be like bellow
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
class CustomLink extends \Magento\Framework\View\Element\Template { public function __construct(Template\Context $context , array $data = []){ parent::__construct($context , $data); } private $_links = []; protected function _toHtml() { $html = "<ul class ='custom-link'>"; foreach($this->_links as $link) { $html .= "<li><a title='" . $link['title'] . "' href=''" . $link['url'] . "></a> ." . $link['label'] . "</li>"; } $html .= "</ul>"; return $html; } public function addLink($url , $label , $title = "") { $this->_links[] = [ "title" => $title , "label" => $label , "url" => $url ]; } } |
after create block you need pass some data to block. I wanna use XML for this
1 2 3 4 5 6 7 8 9 |
<referenceContainer name="center-footer"> <block name="custom-link" class="Vendor\Module\Block\CustomLink"> <action method="addLink"> <argument name="url" xsi:type="string">url</argument> <argument name="label" xsi:type="string">lbl</argument> <argument name="title" xsi:type="string">ttt</argument> </action> </block> </referenceContainer> |
You can use this XML code on any layout like default.xml.
I hope this post helped you