How do I include images in a Magento module?

How do I include images in a Magento module?

September 2, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How do I include images in a Magento module?

Including Images in a Magento Module: A Comprehensive Guide

As a seasoned Magento developer, I understand your frustration when trying to include images within your module. The documentation can be sparse, and finding the right folder structure is often elusive. In this guide, we’ll walk through the process step-by-step, ensuring you have a clear understanding of where to place your images and how to reference them in your module.

Step 1: Understanding the Folder Structure

Firstly, let’s clarify the Magento folder structure relevant for your use case:

  • The design directory is indeed the correct place for theme-related files. However, it primarily contains configuration files for layouts and themes.
  • The skin directory, located at the root level of your Magento installation (/skin), is where you should place all static files like CSS stylesheets, JavaScript files, and most importantly, images.

Step 2: Placing Your Images

For your module-specific images, create a folder within the skin directory that corresponds to your theme. Here’s an example:

mage/your-theme

Within this new folder (your-theme), you should create another folder for your module:

mage/your-theme/your-module

Place all of your images within this your-module folder.

Step 3: Referencing Your Images

Now that your images are in the correct location, let’s discuss how to reference them from your module files. You’ll need to use a variable for your module path:

$modulePath = Mage::getBaseDir('skin') . '/your-theme/your-module';

This PHP code uses Magento’s built-in function Mage::getBaseDir() with the parameter 'skin' to get the absolute path of the skin directory. It then concatenates this path with your theme and module folder names.

Step 4: Including the Images in Your Views

To display these images on your webpage, you’ll need to include them within your template files (phtml) or layout XML files.

For PHTML files:

<img src="<?php echo $this->getSkinUrl('your-module/your-image.jpg') ?>" alt="Your Image">

The getSkinUrl() method is a helper function that generates the full URL to a skin file (image, CSS, JavaScript).

For layout XML files:

<reference name="content">
    <block type="core/text" name="your-block-name" template="your-module/your-template.phtml"/>
</reference>

In this example, replace your-block-name with the identifier of your block and your-template.phtml with the name of your PHTML file containing the image reference.

Conclusion

Including images in a Magento module is a straightforward process once you understand the folder structure. By placing your images within the appropriate theme-specific folder under skin, and referencing them using Magento’s builtin functions, you can easily display these assets on your webpage without cluttering your module directory.

Remember that keeping your images organized by theme and module makes maintenance easier in the long run. If you’re looking for more advanced techniques or a comprehensive guide to Magento development, I recommend checking out our detailed tutorials at Laravel Company’s Magento Development Resources.

Happy developing!

Extensions Themes Configuration Import/Export

Our network