SmartFAQ is developed by The SmartFactory (http://www.smartfactory.ca), a division of InBox Solutions (http://www.inboxsolutions.net)

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     19932  reads 
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"}>
    <!-- do 
some stuff here if current module is news -->
<{else}>
    <!-- do 
some stuff for all other situations -->
<{/if}>
This code can be usefull in many situations. But it is up to you, to use this snippet the way you need it.


The comments are owned by the author. We aren't responsible for their content.
user

 Thanks Chapi!


A useful add on... thanks for your contribution.

 
user

 Re: Thanks Chapi!


Oooh, really good. Thanks.

 
user

 This looks really interesting


This article is cool & explains a few good techniques. I am wondering if it could help me with my current problem.

I want to display a block (or single line of php code) without the block header on the top of each modules center page. What i mean by this is something like

<h4 id="centerheading"><{$xoops_pagetitle}></h4>


To appear at the very top of every modules center section.

I Have tried to do this by creating a blobk in php mode but dont quite know what to type. i get php exec errors..

any ideas if this is even possible with xoops?

 
user

 Re: This looks really interesting


Why don't you simply add this line in the module template itself?

 
user

 Not a good suggestion


This suggestion goes against the principle of keeping code separate from presentation, and is also completely unnecessary. If you want module-specific header images, make the changes to the module template!

It is so much easier working with templates that don't contain code - this is a step backwards, in my opinion, negating the benefits that Smarty gives you.

But that's just my opinion, of course

Rowd

 
user

 Re: Not a good suggestion


Well, let's magine slightly different situation - if different images are needed for different themes (dark and light, as easiest example).
Currently you have only one way - overwrite original files... But - what happened, if you have
- different themes
- allow users select themes

You can't change images automagically, you can't switch template automatically
thus - you can handle only
one theme - obe image-set
situation

If (and when) all blocks in all modules are theme-aware, using same trick (for $xoops_theme) - problem can be solved

And I can't see really nothing more, than presentation in this idea.
And see missing now flexibility

 
user

 Re: Not a good suggestion


The only non-presentation code in this suggestion is the code to retrieve the module directory name... perhaps something we should have in the core instead of this.

 
user

 Re: Not a good suggestion


rowdie, if you want to display different module-specific site-logos on your site for example, you can't put that in your module templates. Because the site logo can't be found in the module template, it is located in the theme.html! And the theme.html doesn't know which module is currently active. But with the above code snippet this is possible.

I think adding some lines somewhere in the core to add this as a smarty variable to the theme.html would be great Mithrandir

 
user

 URL directory instead of module directory?


Very Helpful.

I wonder if there is a way to do this based upon the current directory in the URL instead of the directory for the module ($xoops_cmod).

My concern is, this might limit the header graphic changes to a particular module. If one is using tinycontent, for example, they might want a different graphic to display for various pages... instead of just one for all tinycontent pages.

For example, one might use ModRewrite to make a certain tinycontent page come up when a user types a certain URL.

Which takes me back to the original question. Is there a variable that returns the current directory in the URL instead of the module directory?

Helpful tip, either way. Thanks.

 
user

 switching style sheets


Quote:

You can also use this variable as a switch for including stylesheets or templates.


Can someone provide the code and location of the code to allow for different style sheets.

 
user

 Re: switching style sheets


hello terry,

think this is the way chapi will change stylesheets for different modules, isn't it?

<style type="text/css">
<!--
@
import url(<{$xoops_imageurl}>stylie<{$xoops_cmod}>.css);
-->
</
style>


of course you can use

<link rel="stylesheet" type="text/css" media="screen" href="<{$xoops_imageurl}>stylie<{$xoops_cmod}>.css" />


instead.
as always ...

have fun! and happy new year to you!
Didn't read my articles ??
michael

 
user

 Re: switching style sheets


Quote:

have fun! and happy new year to you! Didn't read my articles ??


Same to you Michael, and yes I did read your articles.

thanks,


cheers,
terry

 
user

 Re: Not a good suggestion


Quote:

Poster: Mithrandir Posted: 2005/1/5 8:22:27
The only non-presentation code in this suggestion is the code to retrieve the module directory name... perhaps something we should have in the core instead of this.

You can put something in the header.php after the xoops_pagetitle assign

Edit: here the code;
File: header.php
Line 93 (approx)
// set page title
$xoopsTpl->assign('xoops_pagetitle'$xoopsModule->getVar('name'));

Add
// set chmod
$xoopsTpl->assign('xoops_chmod'$xoopsModule->getVar('dirname'));

Line 113 (approx)
// set page title
$xoopsTpl->assign('xoops_pagetitle'$xoopsModule->getVar('name'));

Add
// set chmod
$xoopsTpl->assign('xoops_chmod'$xoopsModule->getVar('dirname'));

 
user

 Re: Not a good suggestion


I must express my deep gratefulness to Chapi for this concept! It makes creating a cool theme much more confusing and complex. Couldn't live without it.

This only works for module names though. Any thoughts on how to achieve a similar effect with edituser.php and userinfo.php. "System" is too broad for my purposes.

 
user

 Re: Not a good suggestion


Be interested in hearing more also! :)

 
user

 Re: Not a good suggestion


Okay, while you're all thinking about my previous question...

I've got another one for you. What does it mean when I get the following error:
"Call to a member function on a non-object"
from the following line:
"$GLOBALS['xoopsTpl']->assign( 'xoops_cmod', $dirname );"
in one of the modules I have installed. Oh yes, and how might I fix it?

 
user

 Re: Thanks Chapi!


will this work with 2.2.3a

Thanks

 
user

 Re: Thanks Chapi!


Tjnemez, yes it will - but I've added in the FAQ, why the <{php}> section is no longer needed in 2.2.3 as the <{$xoops_dirname}> holds the desired value.

 
user

 Re: Thanks Chapi!


Quote:

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"


So, where do i add <{$xoops_dirname}> in my code? I assume it goes in the theme.html <head>

thanks mith

 
user

 Re: Thanks Chapi!


Quote:

So, where do i add <{$xoops_dirname}> in my code?

Wherever you would use <{$xoops_cmod}> before.

 
user

 Re: Thanks Chapi!


thanks Mith, works great!

 
user

 Re: Thanks Chapi!


Mith - could you use a similar trick to change the block layout on theme.html depending on the current module?

eg - with a forum remove all right hand blocks?

 
user

 Re: Thanks Chapi!


Quote:

could you use a similar trick to change the block layout on theme.html depending on the current module?

Certainly.

However, I would recommend that removing right hand blocks be done through the blocks administration, setting the right blocks to not show up on forum pages.

 


Login

Who's Online

77 user(s) are online (1 user(s) are browsing XOOPS FAQ)


Members: 0


Guests: 77


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Jul 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Did you know ?

You can modify the confirmation email send to your new users

Random question

How do i remove or change the xoops link thats at the bottom of every page?