17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 3911 Views |
-
how add javascript file

7 October 2008 at 11:26pm
Hi!
I try to modify menu of qa download tempate and to do this I need javascript file..so I have:chrome.css file that include css related to the menu
chromejs directory that include chrome.js file whit javascript codeThe theme directory is caracterized by 3 folder:
templates
css
imagesso where I put my file?
I put chrome.css in css folder and chromejs in template (here there is page.ss where I call chrome.js in this way:
<script type="text/javascript" src="chromejs/chrome.js">
</script>
)Then in pagse.ss, in the standar div I add
<div class="chromestyle" id="chromemenu" id="Navcontainer">
<% include Navigation %>
</div>What is wrong?
-
Re: how add javascript file

8 October 2008 at 5:48am
Have you flushed the template cache afterward by visiting the page URL you're modifying and adding ?flush=1 to the end of it? i.e domain.com/page/?flush=1
Another way is to add it in the controller of the page type - http://doc.silverstripe.com/doku.php?id=requirements
-
Re: how add javascript file

8 October 2008 at 7:47pm
Yes, I use correctly ?flush. I try also the second solution but something is wrong, why?
-
Re: how add javascript file

8 October 2008 at 8:12pm Last edited: 8 October 2008 8:15pm
The best way to add your CSS and Javascript is using Requirements::themedCSS() for CSS, and Requirements::javascript() for Javascript on the init() methods for your controllers.
e.g. in Page.php
class Page extends SiteTree {
...
}class Page_Controller extends ContentController {
function init() {
parent::init();Requirements::themedCSS('myCustomCSSFile');
Requirements::javascript('themes/' . SSViewer::current_theme() . '/javascript/jquery-1.2.6.pack.js');
}}
Make sure you have your theme directory structure like this:
- themes
- blackcandy
- css
- javascript
- templates
- mytheme
- css
- templatesMake sure that in order to use "mytheme", for example, you change the SSViewer::set_theme() to SSViewer::set_theme('mytheme') inside mysite/_config.php
Hope this helps!
Sean
-
Re: how add javascript file

10 October 2008 at 2:17am
Sorry but I have problem:
my file are chrome.js and chromestyle.cssI insert chrome.js in theme/mytheme/javascript and chromestyle.css in theme/css.
then in mysite/code/Page.php and tutorial/code/Page.php I add
Requirements::themedCSS('chromestyle.css');
Requirements::javascript('themes/' . SSViewer::current_theme() . '/javascript/chrome.js');What is wrong?nothing seems go well.
thanks..
| 3911 Views | ||
|
Page:
1
|
Go to Top |



