:::: MENU ::::

Magento 2 get static url or skin url

magento2 get static url or skin url

Today we talk about how to Magento2 get view or skin url in you phtml file. For example you image is located in folder web/images. simply add below code with image path and image name.

<?php echo $block->getViewFileUrl('images/test.png') ?>


If you want to add in cms page simple add with image path.

{{view url='images/test.png'}}

If you want to get specific module image in web folder. In my case Module name QaisarSatti_HelloWorld

<?php echo $block->getViewFileUrl('QaisarSatti_HelloWorld::images/test.png'); ?>

If you want to get image url in your block file.


If you want to see where   $block->getViewFileUrl()  method define. You will see every Magento\Framework\View\Element\Template file extends from Magento\Framework\View\Element\Template that extends with Magento\Framework\View\Element\AbstractBlock.php.

you can View on line 762 this method getViewFileUrl is define.

Author: Qaisar Satti
Category: Magento 2
Last Modified: July 12, 2018


So, what do you think ?