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.

Template Questions /

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

Requirements::javascript can't load my js file


Go to End


8 Posts   5065 Views

Avatar
deLisle

Community Member, 12 Posts

14 March 2009 at 12:53am

Hi.

I've created a new Page type. The template for this page type i've put in the Layout folder.

Now when i try to add Requirements::javascript( 'myjsfile.js' ); I know it needs to be in function init in the controller.

It doesn't add it to my main Page.ss file.

Any ideas?

Avatar
Carbon Crayon

Community Member, 598 Posts

14 March 2009 at 2:02am

Hi DeLisle, welcome to Silverstripe :)

You need to put the full path of your file in there, so something like:

Requirements::javascript( 'mysite/javascript/myjsfile.js' );

Silverstripe is smart in that if it doesn't find your file at the specified path it wont try to include it.

Avatar
deLisle

Community Member, 12 Posts

14 March 2009 at 2:07am

Thanks for your reploy however,
i've alread tried adding the full path, it doesn't help.

Avatar
Carbon Crayon

Community Member, 598 Posts

14 March 2009 at 2:23am

hmm thats strange, it can only be one of two things, either the path is wrong on the innit function syntax is wrong, could you post your innit() code?

Avatar
Ingo

Forum Moderator, 801 Posts

14 March 2009 at 2:28am

Andrew is using a heavily customized SSViewer implementation, so the problem is most likely not in SilverStripe core :)

Avatar
deLisle

Community Member, 12 Posts

14 March 2009 at 2:29am

Yeah, what Ingo said. :)

Avatar
Carbon Crayon

Community Member, 598 Posts

14 March 2009 at 2:36am

ahh ok.....no idea then! :)

Avatar
Markiv

Community Member, 2 Posts

21 April 2012 at 9:42pm

i have placed my .js file in mysite/code/page.php ... like

public function init() {
parent::init();

Requirements::javascript("themes/my-theme/js/jquery.js");
Requirements::javascript("themes/my-theme/js/cufon-yui.js");
Requirements::javascript("themes/my-theme/js/Avenir_Next_LT_Pro_500.font.js");
Requirements::javascript("themes/my-theme/js/Avenir_Next_LT_Pro_600.font.js");
Requirements::javascript("themes/my-theme/js/Adelle_Rg_italic_400.font.js");

}

for now i need to Write some code like

<script type="text/javascript" src="js/Avenir_Next_LT_Pro_500.font.js"></script>
<script type="text/javascript">
Cufon.replace('.block1-title');
Cufon.replace('.news-title');
</script>

how can i write code linke this... in siverstripe

plz any one help !!!

Thanks in advance