0

How should I create the link to internal page in a template file ?

For instance, I have a subcategory which URL key is education, how should it be called in my phtml file to get the page http://my.website.com/education.html ?

I'm currently using this:

<a href="<?php echo $block->getUrl('education.html') ?>">
DevonDahon
  • 879
  • 1
  • 15
  • 33

1 Answers1

0

As I understand you are trying to get subcategory url with url key . here is solution - Define objectmanager in your block-

$category = $block->_objectManager->create('Magento\Catalog\Model\Category')
->getCollection()->addFieldToFilter('url_key',$URL_KEY)->getFirstItem();

 $url = $category->getUrl(); 

?>"

use it like this

Piyush
  • 5,893
  • 9
  • 34
  • 64
  • Thanks for the reply but using _objectManager is not recommended. You can read this post about it: https://magento.stackexchange.com/questions/117098/magento-2-to-use-or-not-to-use-the-objectmanager-directly – DevonDahon Nov 16 '17 at 12:49