Linking to Theme Images and Assets in Magento 2

Linking to Theme Images and Assets in Magento 2

Magento 2 serves theme assets from generated static paths, so hard-coding URLs breaks easily. Use these helpers instead.

The helpers

{{view url=''}} // In Block and CMS Pages

$block->getViewFileUrl() // in Phtml or on php

Use the directive in CMS pages and blocks, and $block->getViewFileUrl('images/logo.svg') in templates. Both resolve the correct path for the current theme and locale.

Need a second pair of eyes on this? Our team handles Magento development every week. See how we can help.

Keep reading

Related articles

All articles

Need a hand?

Stuck on something similar?
We can fix it with you.

Send us the problem. A senior developer reads every message and replies within one working day.