Using Javascript
Generating the URL for Javascript resources
You can generate the URL for an Javscript resource with the url_for_javascript controller method. This will return a URL pointing to the resource. For example,
[my url_for_javascript _woof.js]
will generate
The file is located as described in the Locating static resources chapter with public/js as the search root.
Alternatively, you can also pass in relative or absolute URLs (though the latter is only useful in the context of include_javascript described below). For example, a relative URL can be passed in as
[my url_for_javascript js/_woof/_woof.js]
which will generate
Note that the relative URL is always assumed to be relative to the URL root for the Woof! application.
Generating a link to load Javascript
Alternatively, you can generate the entire link to load a Javascript script with the include_javascript controller method. Any additional attributes can also be passed to the command. For example,[my include_javascript http://example.com/absolute/url/script.js]
will generate
Including Javascript in the default layout
The default layout will
automatically include links to Javascript resources if the
pagevar object contains the element
scripts
. See the
Default page layout chapter for more details.