1
trabis
How to correctly add scripts in your XOOPS theme
  • 2010/7/24 21:47

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 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!

2
Catzwolf
Re: How to correctly add scripts in your XOOPS theme
  • 2010/7/24 22:02

  • Catzwolf

  • Home away from home

  • Posts: 1392

  • Since: 2007/9/30


You don't need the full url there, just

Quote:

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


$xoTheme will add the url automatically for you. :)

3
trabis
Re: How to correctly add scripts in your XOOPS theme
  • 2010/7/25 17:53

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


There is some code missing for legacy support.
Better solution can be found here:
http://www.xuups.com/modules/mynews/article.php?storyid=17

4
Catzwolf
Re: How to correctly add scripts in your XOOPS theme
  • 2010/7/25 18:50

  • Catzwolf

  • Home away from home

  • Posts: 1392

  • Since: 2007/9/30


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.

Login

Who's Online

245 user(s) are online (134 user(s) are browsing Support Forums)


Members: 0


Guests: 245


more...

Donat-O-Meter

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

Latest GitHub Commits