How can I display different images or include different stylesheets according to the currently viewed module?

Requested and Answered by Chapi on 2004/12/28 12:13:42

How can I display different images or include different stylesheets according to the currently viewed module?

The following code snippet will help you to get the directory name of the currently viewed module in your theme.html You have to add the following snippet at the very top of your theme.html in the respective folder (/themes/yourtheme/theme.html). The templates_c folder just compiles the content of the themes folder.

<{php}>
$mod $GLOBALS['xoopsModule'];
$dirname = (isset($mod) ? $mod->getVar('dirname') :'system');
$GLOBALS['xoopsTpl']->assign'xoops_cmod'$dirname );
<{/
php}>
After you have added this (without any changes) you can access the current module directory through the following smarty variable.
<{$xoops_cmod}>
The dirname for the news module is normally "news". So if you are browsing the news module, the variable $xoops_cmod will contain "news". If you are browsing your profile it will contain "system". NOTE FOR XOOPS 2.2.3 (added by Mithrandir): The above code also works on 2.2.3, but is not needed, as <{$xoops_dirname}> is globally available in themes and holds the directory name of the currently selected module - defaulting to "System" With this you can display different images on each module. Just try the following snippet:
<img src="<{$xoops_imageurl}><{$xoops_cmod}>.jpg" alt="" title="" />
$xoops_imageurl is the path to your themes folder. So you have to create a few images there, one for each of your installed modules and an additional one for the system. - system.jpg - news.jpg - newbb.jpg .. and so on. You can also use this variable as a switch for including stylesheets or templates.
<{if $xoops_cmod == "news"}>
    
<{else}>
    
<{/if}>
This code can be usefull in many situations. But it is up to you, to use this snippet the way you need it.

This Q&A was found on XOOPS Web Application System : https://xoops.org/modules/smartfaq/faq.php?faqid=335