1

I have created one module but module images and css not accessible from web folder. its access only one time. second time not accessible.

http://localhost/mage2ex/pub/static/frontend/_view/en_US/NS_Module/images/defaultbg.jpg

We have try $block->getViewFileUrl() and $this->getViewFileUrl() but no luck with this.

I don't know why added _view in /mage2ex/pub/static/frontend/_view/

1

You can access images directly in your custom Module images e.g Vendor_Module/view/frontend/web/images/my_image.jpg can be accessed in css as follow:

background-image: url('@{baseDir}Vendor_Module/images/my_image.jpg');
0

After created module when you apply commands and run your website your css and js will be loaded first time and it will display from cache folder like

pub/static/frontend/...

so your frontend will execute fast

1

Finally i got solution using parameter with $block->getViewFileUrl();

echo $block->getViewFileUrl('NS_Module::js/jquery-1.12.4.min.js', array(
    'area'  => 'frontend',
    'theme' => 'Magento/luma'
));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.