trabis trabis
  • Core Developer
  • Core Developer
  • Joined: 2006/9/1 14:10
  • From Portugal
  • Group: Webmaster Registered Users
  • Posts: 2253
  • Posted on: 2010/7/24 17:47
How to correctly add scripts in your XOOPS theme #1
If you want to add scripts or stylesheets in your theme do not hardcoded them in the header.

Hardcoding it will probably cause duplication if some other module include the same file.

The solution is using Xoops API that already handles duplicate files.

So instead of just using <{$xoops_module_header}> ,you need to do the following:
<!-- RMVadded module header -->
  <{
php}>
    global 
$xoTheme;
    
$xoTheme->addScript('http://yoursite.com/somescript.js');
    
$xoTheme->addStyleSheet('http://yoursite.com/somesstyle.css');
    
$this->assign('xoops_module_header'$xoTheme->renderMetas(nulltrue));
  <{/
php}>
  <{
$xoops_module_header}>


Have fun!
Catzwolf Catzwolf
  • Home away from home
  • Home away from home
  • Joined: 2007/9/30 0:21
  • Group: Registered Users
  • Posts: 1392
  • Posted on: 2010/7/24 18:02
Re: How to correctly add scripts in your XOOPS theme #2
You don't need the full url there, just

Quote:

$xoTheme->addScript('somescript.js');


$xoTheme will add the url automatically for you. :)
trabis trabis
  • Core Developer
  • Core Developer
  • Joined: 2006/9/1 14:10
  • From Portugal
  • Group: Webmaster Registered Users
  • Posts: 2253
  • Posted on: 2010/7/25 13:53
Re: How to correctly add scripts in your XOOPS theme #3
There is some code missing for legacy support.
Better solution can be found here:
http://www.xuups.com/modules/mynews/article.php?storyid=17
Catzwolf Catzwolf
  • Home away from home
  • Home away from home
  • Joined: 2007/9/30 0:21
  • Group: Registered Users
  • Posts: 1392
  • Posted on: 2010/7/25 14:50
Re: How to correctly add scripts in your XOOPS theme #4
I fear this will lead to more problem in the long run.

I really do not understand this approach when this should have been handled by the template class? Really, xoTheme should check whether or not the file has been added before and take the required steps to prevent compatibility issue.

Instead we create another file and class to do this and thus instead of making the process simple we begin to complicate the issue further.

Doing this is simple:
$xoTheme->addScript('somescript.js');

Doing this begins to create problems:

$xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');

Why? Because we could have easily did a check to see whether the javascript was 'JQuery.js' and used the correct version from xoTheme or template class and this way compatibility wouldn't have been affected in the short or long run.

Or better still:

$xoTheme->addJQuery();
$xoTheme->addJQueryUI();

Again we complicate things when there is no need to.
How to effectively post a question in the Xoops forums? - Read here...
Design by: XOOPS UI/UX Team