Block file :
namespace Test\Module\Block;
class Product extends \Magento\Framework\View\Element\Template
{
protected $storeManager;
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Store\Model\StoreManagerInterface $storeManager
) {
$this->storeManager = $storeManager;
parent::__construct($context);
}
public function getBaseUrl()
{
$currentStore = $storeManager->getStore();
return $currentStore->getBaseUrl();
}
public function getMediaUrl()
{
$currentStore = $storeManager->getStore();
return $currentStore->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
}
public function getLinkUrl()
{
$currentStore = $storeManager->getStore();
return $currentStore->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK);
}
}
Phtml file :
echo $this->getBaseUrl();
echo $this->getMediaUrl();
echo $this->getLinkUrl();
?>