Reputation: 2699
in a silverstripe project I´m loading whole pages via ajax. Therefore I added to the Page-Contoller following function:
public function ajax(){
return $this->renderWith('MyTemplate');
}
This works fine so far and I get the page rendered as I want when browsing to mysite.com/mypage/ajax. The only Problem are the included JS/CSS Files in the template "MyTemplate":
<% require javascript(my.js) %>
<% require css(my.css) %>
The css/js does not show up in the source code - somehow it is not included, although it is part of the template "MyTemplate".
So is there a way to add the css/js in a cool way with silverstripe methods?
I tried this:
public function ajax(){
Requirements::css("my.js");
return $this->renderWith('ProjectPage');
}
but no success so far. Many thanks, Florian
Upvotes: 1
Views: 1242
Reputation: 6409
You need to load the following javascript file into your site, depending on silverstripe version:
SS3 - /framework/javascript/jquery-ondemand/jquery.ondemand.js
OR
SS2.4 -/sapphire/javascript/core/jquery.ondemand.js
As far as I understand; when you make an ajax request, any new css or javascript requirements are added into the the request header. Then when the request is successful, ondemand.js pulls those scripts into the document for you, if they are not already there.
Upvotes: 1