Hey guys,
I was testing some of my extension code and ran into a problem. How do you reference images for a module/extension in the CP?
So far I have tried:
'" . $PREFS->ini('site_url') . $PREFS->ini('system_folder') . "/extensions/lg_twitter_ext/bg.png'
Fails when you browse to a secondary msm site
'/" . $PREFS->ini('system_folder') . "/extensions/lg_twitter_ext/bg.png'
Fails when the user has EE installed in a sub folder
The only reliable way seems to be throwing all the files in a new folder in the themes directory as the user has to type this in manually.
I have seen Solspace call another CP page that returns the JS/CSS but this seems like a bit of overkill.
Any ideas?
Well typically i do this:Even if people mask their CP it will still work since the original CP url is always accessible. Or am i wrong? I guess that’s why Solspace went for the “themes” solution, since that always works..$this->lib_path = $PREFS->ini('site_url', TRUE).$PREFS->ini('system_folder', TRUE).'modules/'.$this->module_name.'/lib/';
The issue with that approach is that a msm site has a different site url which doesn’t contain the EE installation. :( So the assets are 404
Ok answering my own post here but I think the best way to reference images and scripts for extensions and modules is to:
$PREFS->ini('theme_folder_url', 1) . "cp_themes/".$PREFS->ini('cp_theme')."/lg_twitter/admin.js"
This way your extension can be tweaked for custom cp themes in the future. Seems ok and is fail proof on msm sites and masked CPs
Seems reasonable from here. I took a look- Tag is using the THEME_FOLDER constant, which is defined in core.system.php
// ----------------------------------------------
// Theme Paths
// ----------------------------------------------
if ($PREFS->ini('theme_folder_path') !== FALSE && $PREFS->ini('theme_folder_path') != '')
{
$theme_path = preg_replace("#/+#", "/", $PREFS->ini('theme_folder_path').'/');
}
else
{
$theme_path = substr(PATH, 0, - strlen($PREFS->ini('system_folder').'/')).'themes/';
$theme_path = preg_replace("#/+#", "/", $theme_path);
}
define('PATH_THEMES', $theme_path);
define('PATH_SITE_THEMES', PATH_THEMES.'site_themes/');
define('PATH_MBR_THEMES', PATH_THEMES.'profile_themes/');
define('PATH_CP_IMG', $PREFS->ini('theme_folder_url', 1).'cp_global_images/');
if (REQ == 'CP')
{
define('PATH_CP_THEME', PATH_THEMES.'cp_themes/');
}
unset($theme_path);
But I’m not dead sure what the preferred approach is. Took a look at the file upload button in publish, it’s using
/** --------------------------------
/** Upload link
/** --------------------------------*/
$up_img = ''.PATH_CP_IMG.line('file_upload').'" >';
I’m going to shift this down to ‘Modules’ and give the crew a bump on it.
Hey Robin,
Thanks for your input. Using the PATH_CP_IMG variable and the $PREFS->ini(‘theme_folder_url’, 1) method is the only foolproof way I have found so far.
Honestly its not too much extra time to implememnt but it does mean that the installation has a couple of extra steps. Unfortunatley sometimes that’s all it takes to confuse someone.
Cheers
I was wondering if anyone gave this some extra thought (preferably the developers at EllisLab)?
The ideal situation would be to have a directory called css/img/js in your module directory to simplify installation, but how does one get the path to that folder in a foolproof way? I intend to use this module I’m developing myself, but making things easier is never a bad thing…
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.