Jump to:

23454 Posts in 17971 Topics by 2863 members

General Questions

SilverStripe Forums » General Questions » Custom javascript with additional page types problem

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 1200 Views
  • Harley
    Avatar
    Community Member
    153 Posts

    Custom javascript with additional page types problem Link to this post

    Hello, first of all what an amazing CMS Silverstripe is! When is the book due for release?

    I have a small problem with a site I'm building at the moment. I have some custom css and javascript I'm running for some progressive enhancements on my navigation.

    The trouble is that when I use a page type other than the default 'Page' it is not picking up the extra javascript files.

    This is what my Page.php looks like:

    class Page_Controller extends ContentController {
       
       public function init() {
          parent::init();

          Requirements::themedCSS("layout");
          Requirements::themedCSS("typography");
          Requirements::themedCSS("form");
          Requirements::themedCSS("navigation");
          Requirements::javascript("http://localhost/wwwroot/elevator/themes/elevator/javascript/jquery-1.3.2.js");
          Requirements::javascript("http://localhost/wwwroot/elevator/themes/elevator/javascript/nav.js");
       }

    Am I right to say that any other page types you create as long as you specify:

    class ContactPage_Controller extends Page_Controller{

    ...should inherit the default Page type classes for requirments? It seems to pick up the css but not the javascript files.

    One more thing, I've come this far and this my first time developing with Silverstripe. I'm a bit confused however as to how I write my paths, as you will see above I have written the absolute path to get working results, when trying relative it simply doesn't work. What am I doing wrong here? Need to know for when I go live with this beast!

  • Willr
    Avatar
    Forum Moderator
    5482 Posts

    Re: Custom javascript with additional page types problem Link to this post

    All paths are usually relative from your root domain or root SS folder (depending on where you are talking about) So..

    Requirements::javascript("themes/yourtheme/javascript/afile.js"); will point to that path.

    ThemedCSS is a shortcut to themes/yourtheme/css so Requirements::themedCSS("layout"); is the same as Requirements::css("themes/yourtheme/css/layout.css"). Currently themedJavascript() does not exist which is why for JS you have to use the path like above.

    ...should inherit the default Page type classes for requirments? It seems to pick up the css but not the javascript files.

    Correct. It should pickup the JS files aswell. Update your code to the proper relative path and try again. Make sure also that the JS isn't just loaded to the bottom of the page (which SS does for performance)

  • Harley
    Avatar
    Community Member
    153 Posts

    Re: Custom javascript with additional page types problem Link to this post

    Will, thanks for the reply

    Yes you are right, the javascript files are all at the bottom of the page. How can I make these sit in the head tag?

    Also, I am only using jquery, is there a way for me to turn off the other libraries?

    Regards

  • Harley
    Avatar
    Community Member
    153 Posts

    Re: Custom javascript with additional page types problem Link to this post

    I have now sorted out my problem

    Thanks for the advice

    1200 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.