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.

General Questions /

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

Javascript problems with Silverstripe


Reply


5 Posts   1205 Views

Avatar
Luis

Community Member, 2 Posts

21 July 2010 at 12:41am

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?

Avatar
swaiba

Forum Moderator, 1799 Posts

21 July 2010 at 2:09am

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>

Avatar
Luis

Community Member, 2 Posts

21 July 2010 at 5:09am

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!

Avatar
swaiba

Forum Moderator, 1799 Posts

21 July 2010 at 5:34pm

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

Avatar
Willr

Forum Moderator, 5513 Posts

21 July 2010 at 7:26pm

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