I'm new to magento and learning hard thesedays. I have a task to display an image using raw controller but couldn't really find out how to do this. I have my image on etc/frontend/web/images as shown on the screenshot. [1]: https://i.stack.imgur.com/JMNmW.png

and my raw controller code is as below.


class Raw extends Action { protected $raw;

public function __construct(
    Context $context,
    Raw $raw
    $this->raw = $raw;

public function execute()
    $result = $this->raw->create();
    $result->render('<img src="../etc/frontend/web/images/Japan_bg.png"/>');
    return $result;



I know this code is really bad... I have found a way to print image URL but display... is there anyone who can help me out with this please?

Many thanks!!

  • You can use template to display image, learn how to display a simple block/template
    – Jimmy
    Mar 22, 2021 at 3:19

1 Answer 1


You can display your images in the model of magento. You can refer to this article: https://www.mageplaza.com/magento-2-module-development/view-block-layout-template-magento-2.html

Your Answer

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

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