Jump to:

23373 Posts in 18175 Topics by 2865 members

General Questions

SilverStripe Forums » General Questions » Javascript problems with Silverstripe

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: 1161 Views
  • Luis
    Avatar
    Community Member
    2 Posts

    Javascript problems with Silverstripe Link to this post

    I am creating a site that have javascript that allows two columns or any number of columns to keep the same height no matter the content of each column.

    I placed the javascript at the mysite/javascript directory as the documentation stated. Since these two scripts are used in the site I make the following entry in mysite/code/Page.php:
    Requirements::javascript('mysite/javascript/jquery.brenelz.equalHeight.js');
    Requirements::javascript('mysite/javascript/jquery-1.2.6.pack.js');
    Requirements::customScript("$(function(){
    $('.column').equalHeight();
    });");

    However when the site is previewed or uploaded by the browser it display the javascripts at the bottom of the page instead between the <header> tag, just before </body></html>tags. And also the column of the left has a background color and has less content than the right column...in a standard environment using the layout created for this site (regular HTML page) the background color is displayed with the same height of the column that does not have color. But in the stilverstripe page I notice checking the that the background color does not show all the way down and the javascripts are put at the bottom of the page instead in between the header on top and that is why my script does not work.

    Please let me know what I am doing wrong?

  • swaiba
    Avatar
    Forum Moderator
    1785 Posts

    Re: Javascript problems with Silverstripe Link to this post

    I would not say you are doing anything "wrong". There may be a conflict with the version of jQuery (I've had to fiddle with this before to get things working) - but other than that you can put the includes into relevant \templates\Page.ss and make sure they are in the head that way if you like...

    <head>
    ...
    <script type="text/javascript" language="javascript" src="mysite/javascript/yourscript.js"></script>
    ...
    </head>

  • Luis
    Avatar
    Community Member
    2 Posts

    Re: Javascript problems with Silverstripe Link to this post

    Swaiba...Thank you, it works the way that you suggested...but Will be the case in any javascript rather than place them inside mysite/code/Page.php as the documentation required? Remember I am new to Silver Stripe.

    Thank you for your help!

  • swaiba
    Avatar
    Forum Moderator
    1785 Posts

    Re: Javascript problems with Silverstripe Link to this post

    It can depend - some js needs to be defined in the <head> tags and in a certain order - but mostly I find that pieces of js for page functionality can be Requirement::Javascript in the Page::init() function...

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Javascript problems with Silverstripe Link to this post

    SS loads Javascript at the bottom of the page for performance improvements (see http://developer.yahoo.com/performance/rules.html#js_bottom). If you want to disable this and put the scripts normally at the top of the page use the following code in your _config.php file.

    Requirements::set_write_js_to_body(false);

    1161 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.