[SOLVED] Using custom images with a module

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
User avatar
tallphil
Forum Members
Forum Members
Posts: 20
Joined: Sat Jan 30, 2010 8:01 pm
Location: Cambridge, UK

[SOLVED] Using custom images with a module

Post 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
Last edited by tallphil on Mon May 31, 2010 7:39 am, edited 1 time in total.
User avatar
tallphil
Forum Members
Forum Members
Posts: 20
Joined: Sat Jan 30, 2010 8:01 pm
Location: Cambridge, UK

Re: Using custom images with a module

Post 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?
NaN

Re: Using custom images with a module

Post 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.
User avatar
tallphil
Forum Members
Forum Members
Posts: 20
Joined: Sat Jan 30, 2010 8:01 pm
Location: Cambridge, UK

Re: Using custom images with a module

Post 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! :)
Post Reply

Return to “Developers Discussion”