How to Get Base, Media, Skin & Link URL in Magento2?

  • author-img Nidhi Arora
  • 6 years
  • 861 views
How-to-get-base-URL-in-Magento2.jpg May 2, 2016 128 kB 1024 × 600 Edit Image Delete Permanently URL http://demo.envisionecommerce.com/wp-content/uploads/2016/05/How-to-get-base-URL-in-Magento2.jpg Title How-to-get-base-URL-in-Magento2 Caption
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

Free Webinar

Ready to start your eCommerce journey?

Get in Touch
Recent Posts
ENQUIRY

Ready to Get started

Communication is the key for us to understand each other. Allow us to understand
your requirements or queries. Present us with an opportunity to serve you.

Fill out the form and out team will get back to you
within 24 hours

    Head Office

    1250 Pittsford Victor Road Ste 310
    Pittsford, NY 14534

    Development Center

    Plot no. 10, Rajiv Gandhi
    Chandigarh Technology Park