¿Cómo incluyo imágenes en un módulo de Magento?

I want the images to be displayed on the webpage, but included in the Magento module.

  1. Which folder do I put them in?
  2. How do I reference to them? (I'll need a variable for the module path.)

The documentation, various external tutorials and a Google search provides no help.

All I see under design/frontend/default/default carpeta es etc layout locale template and nowhere to put images.

Do I put them in the skin/frontend/default folder? If so, where?

preguntado el 01 de julio de 12 a las 18:07

2 Respuestas

Assuming your module applies to Magento 1.4+, your images belong under ./skin/frontend/base/default/images/, ideally in a folder indicating your module's namespace and name, e.g. namespace_module. They can then be referenced in the following ways:

  • A module CSS file at base/default/css/namespace_module/file.css: url(../../images/namespace_module/image.jpg)

  • A template (or block): $this->getSkinUrl('images/namespace_module/image.jpg')

  • En cualquier lugar: Mage::getDesign()->getSkinUrl('images/namespace_module/image.jpg');

FYI, nothing under the ./app/ directory is accessed (should be accessed) directly by the browser.

Respondido 01 Jul 12, 20:07

Cuando tu dices module's namespace then name, does that mean that I can have my /desbest/showdown carpeta dentro del skin/frontend/default folder, and have Mage::getDesign()->getSkinUrl point to that? - desmejorar

It is only a matter of preference. By convention, I'd say to put your folders inside each asset type folder (css, image, js). The Mage::getDesign()->getSkinUrl() will always point to the configured theme, which will fallback to base/default. - Benmarks

I'm making a magento módulo, no a theme. Because I'm using the default theme, it siempre vuelve a base/default. I want to include images within my module, so I need to know exactly how to do that. - desmejorar

It is useless to point my folders of assets to the specific theme, because the person using my modules might change the theme. That would render my module's assets (img/css/js) as broken. I want to create asset folders for modules, and not for a theme. - desmejorar

...which is what I've explained here. Magento theme assets fall back to the base/default theme, under which you should place your assets. See Mage_Core_Model_Design_Package for the skinny. - Benmarks

An alternative to shipping your image as part of your extension, is to host it on your webserver (or someone else's) and then include it by URL in your extension.

If that's the case, and you want the image to show up on your basic admin pages, then you just put html directly into your system.xml (escape it first). Otherwise, if you're including it in your templates, just put it in with an img etiqueta html.

Couple of benefits to this approach:

1) You can look at your Apache logs each month and see how many times your image got viewed (i.e how many people are installing your extension) and also, from the referer HTTP header, you can see which sites are using it too.

2) When your wildly successful internet company gets acquired, you can easily swap in a different logo.jpg on your webserver, without having to roll out a new version of your extension.

Entonces no es el manera correcta, but it's a simple way with a couple of benefits.

Respondido 02 Jul 12, 09:07

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.