I need to get the url of the image located in the module.
I need to run a Patch script because I am updating a cms block with an additional image.
The image path I am getting is localhost/pub/static/version1655667432/frontend/_view/en_US...
But when I look at the pub folder, the path should be localhost/pub/static/version1655667432/frontend/default/en_US...
try {
$this->_appState->setAreaCode(\Magento\Framework\App\Area::AREA_FRONTEND);
} catch (\Exception $e) {
$this->_appState->getAreaCode();
}
$params = array('_secure' => $this->request->isSecure());
$madeInUsaImgPath = $this->assetRepo->getUrlWithParams('Collins_ShowOnAll::images/made-in-usa.png', $params);
1 Answer 1
You don't need to create any Setup/Patch scripts
For create your own extension you just need to create 2 files in module
Create
registration.php<?php declare(strict_types=1); use Magento\Framework\Component\ComponentRegistrar; ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Acme_StackExchange', __DIR__);Create module declaration
etc/module.xml<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> <module name="Acme_StackExchange"> <!-- optional dependencies --> <sequence> <module name="Magento_Catalog"/> </sequence> </module> </config>Create frontend resource like
view/frontend/web/images/file.png
And access file with Acme_StackExchange/images/file.png from skin
If you have more specific question, please update your question or specify in comment
[Update]
The path to static file contains deploy version in URL and I don't suggest you to use full URL.
For CMS Block/Page you can use directive view
<img src="{{view url='Acme_StackExchange::images/file.png'}}" alt/>
or
<img src="{{view url='Acme_StackExchange/images/file.png'}}" alt/>
If you want to use in template
<img src="<?= $block->getViewFileUrl("Acme_StackExchange::images/file.png"); ?>" alt=""/>
-
I updated the questions description.Justin Collins– Justin Collins2022年06月19日 20:10:36 +00:00Commented Jun 19, 2022 at 20:10
-
See updated comment, i hope this will helpVictor Tihonchuk– Victor Tihonchuk2022年06月20日 07:27:23 +00:00Commented Jun 20, 2022 at 7:27