5121 Posts in 1527 Topics by 1119 members
| Go to End | Next > | |
| Author | Topic: | 4878 Views |
-
Inserting custom javascript

6 July 2009 at 6:56pm
New to this, I'm on page.ss and I'm trying to add some dhtmlgoodies.com javascript for a slide-show, I have managed to use the <% require%> tags to include the css but the javascript isn't working for me, am I doing something wrong? I've tried it with and without the.js but neither are getting my slide show rolling???
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" ><head>
<% base_tag %>
<title><% if MetaTitle %>$MetaTitle<% else %>$Title<% end_if %> » Your Site Name</title>
$MetaTags(false)<link rel="shortcut icon" href="/favicon.ico" />
<% require themedCSS(layout) %>
<% require themedCSS(typography) %>
<% require themedCSS(form) %>
<% require themedCSS(sitetest) %>
<% require themedCSS(image-slideshow) %>
<% require javascript(themes/blackcandy/js/image-slideshow.js) %>Any clues greatly appreciated.
Thanks.
-
Re: Inserting custom javascript

7 July 2009 at 1:17am
Hi Belinda
Try adding this function to your Page_Controller class:
function init() {
parent::init();
Requirements::javascript("themes/blackcandy/js/image-slideshow.js");
}I usually include all my files via the Controller as I find it cleaner and more intuitive. I know you can include CSS via the template, not sure about JS.
Hope that helps
Aram
-
Re: Inserting custom javascript

7 July 2009 at 5:06pm
Thanks for your response, really appreciated.
I tried adding all of what you suggested, and I got a blank page after a flush, so I have inserted just that line at the bottom and the page is loading, but the javascript isn't working. When I view source the include image-slideshow.js script isn't there anywhere?? If you have any other ideas I'd be a happy lady!
class Page_Controller extends ContentController {
public function init() {
parent::init();// Note: you should use SS template require tags inside your templates
// instead of putting Requirements calls here. However these are
// included so that our older themes still work
Requirements::themedCSS("layout");
Requirements::themedCSS("typography");
Requirements::themedCSS("form");
Requirements::javascript("themes/blackcandy/js/image-slideshow.js");}
-
Re: Inserting custom javascript

7 July 2009 at 6:47pm
If the script isn't loading then it means SS hasn't found it, check that the path is correct.
-
Re: Inserting custom javascript

7 July 2009 at 7:41pm
Thanks, I know it must be something like that, but even when I put the whole path in it's not showing up. Grrr
class Page_Controller extends ContentController {
public function init() {
parent::init();// Note: you should use SS template require tags inside your templates
// instead of putting Requirements calls here. However these are
// included so that our older themes still work
Requirements::themedCSS("layout");
Requirements::themedCSS("typography");
Requirements::themedCSS("form");
Requirements::javascript("http://localhost:8888/silverstripe/themes/blackcandy/js/image-slideshow.js");
} -
Re: Inserting custom javascript

7 July 2009 at 8:25pm Last edited: 7 July 2009 8:26pm
Using the path as in your previous posts should work just fine.
- Make sure the path is correct, eg. this file exists: themes/blackcandy/js/image-slideshow.js
- If you're running *nix (that includes mac os x), check the permissions of the file.
- Note, that the javascript file will be included at the bottom of the html code, just before the closing body tag (just in case you were looking at the wrong place...) -
Re: Inserting custom javascript

7 July 2009 at 9:06pm
Doh! Yes, I was looking in the wrong place, it was there. Still not working though. I am running Mac os x, how do I check the file permissions?
Thank you.
-
Re: Inserting custom javascript

7 July 2009 at 9:08pm
Well, if it's there, the permissions are right. There must be an error in the script or something. Or maybe you simply forgot to initialize it? Firebug will help a great deal there (http://getfirebug.com/)
| 4878 Views | ||
| Go to Top | Next > |



