Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Inserting custom javascript


Go to End


16 Posts   10137 Views

Avatar
BelindaBJ

Community Member, 9 Posts

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" xml:lang="en" >

  <head>
		<% base_tag %>
		<title><% if MetaTitle %>$MetaTitle<% else %>$Title<% end_if %> &raquo; 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.

Avatar
Carbon Crayon

Community Member, 598 Posts

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

Avatar
BelindaBJ

Community Member, 9 Posts

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");

	}

Avatar
Carbon Crayon

Community Member, 598 Posts

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.

Avatar
BelindaBJ

Community Member, 9 Posts

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");
  			
	}

Avatar
bummzack

Community Member, 904 Posts

7 July 2009 at 8:25pm

Edited: 07/07/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...)

Avatar
BelindaBJ

Community Member, 9 Posts

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.

Avatar
bummzack

Community Member, 904 Posts

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/)

Go to Top