0

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);
asked Jun 19, 2022 at 19:23

1 Answer 1

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

  1. Create registration.php

    <?php
    declare(strict_types=1);
    use Magento\Framework\Component\ComponentRegistrar;
    ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Acme_StackExchange', __DIR__);
    
  2. 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>
    
  3. 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=""/>
answered Jun 19, 2022 at 19:59
2
  • I updated the questions description. Commented Jun 19, 2022 at 20:10
  • See updated comment, i hope this will help Commented Jun 20, 2022 at 7:27

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.