Fork me on GitHub

Search

Donat-O-Meter

Make donations with PayPal!
Stats
Goal: $100.00
Due Date: Oct 31
Gross Amount: $10.00
Net Balance: $9.41
Left to go: $90.59

Donations
Dante7237  ($10)Oct-30

Learn XOOPS Core

Local Support

Advertisement

XOOPS Code hosted on SourceForge

Cumulus Tag Cloud

- 2 2.5 2.6 3.0 4 6 2013 Abuse Android AntiHarvesting AntiMalUser AntiSpam API Apple Battlefield Blocks Bootstrap Captcha cell chronolabs CHUNG content CĂN demo docek download Dresses evden eve facebook Fat Food for free Gateway Google Guide herre Honeypot HP html5 Human HỘ IP iPhone jQuery Law Legal List Loss mobile module modules Monster new newbb news NHÀ online PARK Payment phone PHP Prevention profile project Protector publisher Rapid RESIDENCE responsive review Rights rmcommon Room security Sentry site Smartphone Smarty Solution Spam Studio support tag tags tdmcreate The Theme themes User userlog web weight Wishcraft xoops Xortify

New Users

Registering user

# 137872

ode64de

Welcome to XOOPS!




Bottom   Previous Topic   Next Topic  |  Register To Post



#1 Posted on: 2010/7/24 16:47 How to correctly add scripts in your XOOPS theme
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!


Top


Xoops User Utilities | Xoops Search Engine | vil3/trabisdementia
trabis
Joined:
2006/9/1 13:10
From Portugal
Group:
Webmaster
Registered Users
Posts: 2198
(Show More) (Show Less)


#2 Posted on: 2010/7/24 17:02 Re: How to correctly add scripts in your XOOPS theme
You don't need the full url there, just

Quote:

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


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

Top

Catzwolf
Joined:
2007/9/29 23:21
Group:
Registered Users
Posts: 1317
(Show More) (Show Less)


#3 Posted on: 2010/7/25 12:53 Re: How to correctly add scripts in your XOOPS theme
There is some code missing for legacy support.
Better solution can be found here:
http://www.xuups.com/modules/mynews/article.php?storyid=17

Top


Xoops User Utilities | Xoops Search Engine | vil3/trabisdementia
trabis
Joined:
2006/9/1 13:10
From Portugal
Group:
Webmaster
Registered Users
Posts: 2198
(Show More) (Show Less)


#4 Posted on: 2010/7/25 13:50 Re: How to correctly add scripts in your XOOPS theme
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.


Top

Catzwolf
Joined:
2007/9/29 23:21
Group:
Registered Users
Posts: 1317
(Show More) (Show Less)







You can view topic.
You cannot start a new topic.
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You can vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create pdf.
You cannot get print page.

[Advanced Search]