1

I am new in magento2. I saw many question but i can't understand flow.

can any one help me how to call cms page in anchor tag ?

I tried some code but it is not working.

<a href="<?php echo $this->getUrl('footer'); ?>">CMS PAGE LINK</a>

Thanks in advance :)

0

You can get url by page ID, Try this flow :-

$pageId = 1;
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$cms_page_url = $objectManager->create('Magento\Cms\Helper\Page')
->getPageUrl($pageId);

Add this code in phtml :-

<a href="<php echo $cms_page_url; ?>">CMS PAGE LINK</a>
1
  • 1
    Happy to help sir ....Happy Coding !!!!!! :) – Rohan Hapani Aug 28 '17 at 19:15
0

In Magento2, if you want to get url then you use $block instead of $this in phtml

<a href="<?php echo $block->getUrl('footer'); ?>">CMS PAGE LINK</a>

$block->getUrl('footer') give the result like SITEURL/footer

In magento2, you want to get a CMS page url in phtml then you use

$_cmsHelper = $this->helper('Magento\Cms\Helper\Page');
$Url =$_cmsHelper->getPageUrl(PAGE_ID);

Additional Info

If you want to get a cms page url by ID then you can get In Block, Helper, Model ,controller classes then you should use inject in __construct()

protected $_pageHelper;
public function __construct(

    \Magento\Cms\Helper\Page $pageHelper,

) {
    $this->_pageHelper = $pageHelper;
}

public function getCmsUrl()
{
    retun $this->_pageHelper->getPageUrl($pageId);
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy