Page 1 of 1

[SOLVED] Using custom images with a module

Posted: Sat May 29, 2010 11:55 pm
by tallphil
Hi there,

I'm writing my first module, it ties into FEU to allow users to add and edit module content (much like the News fesubmit) and I'd like to use icons in the same way that I can in the admin pages with $gCms->variables['admintheme']->DisplayImage

I'm quite happy to use my own icons (I can't help but notice that modules such as MenuManager, FrontEndUsers, ModuleMaker etc have folders of images) but I can't figure out how to reference the images. I haven't managed to find any code in the aforementioned modules doing so either...

So, two questions really:

(a) Is there a 'DisplayImage' equivalent that I should use when outputting a front end page?

(b) If not, how do I get the folder of the module to access the image? Guessing it starts with $gCms-> but haven't managed to get much further than that!  ;)

Cheers all,

Phil

Re: Using custom images with a module

Posted: Sun May 30, 2010 9:11 am
by tallphil
Update:
I've used the following to generate the base directory of my module:

Code: Select all

$moduledir = $gCms->config['root_url'].DIRECTORY_SEPARATOR.'modules'.DIRECTORY_SEPARATOR.
                       '< module name >'.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR;
This still seems a bit pants, anyone know a better way?

Re: Using custom images with a module

Posted: Sun May 30, 2010 5:16 pm
by NaN

Code: Select all


$moduledir = dirname(__FILE__);

This should give you the path to the current used php file.

To refer to your own module images it depends on in what context the image will be displayed.
I mean if it is displayed in a backend panel you create the image like this:

Code: Select all


$img = '<img src="../modules/[MODULENAME]/images/img.gif" />';

If it is shown in frontend you create it like this:

Code: Select all


$img = '<img src="modules/[MODULENAME]/images/img.gif" />';

As i know there is no module function to create images.

The $gCms->variables['admintheme']->DisplayImage stuff is only to display an icon of the current used backend theme.
tallphil wrote:

Code: Select all


$moduledir = $gCms->config['root_url'].DIRECTORY_SEPARATOR.'modules'.DIRECTORY_SEPARATOR.
                       '< module name >'.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR;

Notice that the image need an url.
No path.
That means using DIRECTORY_SEPARATOR in urls is no good idea.

Try this instead:

Code: Select all


$img_dir = $gCms->config['root_url'] ."/modules/[MODULENAME]/images/";

There is no other way to create image urls.

Re: Using custom images with a module

Posted: Mon May 31, 2010 7:38 am
by tallphil
Thanks NaN! Using your solution at the end (which is what I had wound up using independently) seems to work fine, and it's good to know that I'm not unnecessarily reinventing the wheel! :)