How to Get Base, Media, Skin & Link URL in Magento2?
- Nidhi Arora
- 9 years
It is different to get a URL in Magento 2 while comparing it with Magento 1.x. In Magento 1.x, Mage::getBaseUrl() is used to get the base URL. However, Magento 2 supports different methods to get the base, media, skin and link URL. Here is the blog that is going to make clear how you can get the URL in Magento 2.0:
1) To Get Base URL:-
$this->_objectManager->get('Magento\Store\Model\StoreManagerInterface')->getStore($storeId)->getBaseUrl(); $this->_storeManager->getStore()->getBaseUrl();
2) To Get Url for Link:-
$this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK);
3) To Get Media Base Url:-
$this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
4) To Get Skin URl:-
$block->getViewFileUrl(); For admin interface:- {{view url=''}}
Wrapping Up
We hope the above code snippets made it clear how to get base, media, skin, and link URL in Magento 2. If you find Magento 2 development complex and can not really perform such operations seamlessly, you can ask for expert developers’ help here.
Download Blog