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.
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.
Last Modified: January 16, 2018