View Helpers
javaScriptIncludeTag()
Signature
Section titled “Signature”javaScriptIncludeTag() — returns string
Available in: controller
Category: Asset Functions
Description
Section titled “Description”Generates <script> tags for including JavaScript files. Can handle local files in the javascripts folder or external URLs. Supports multiple files and optional placement in the HTML <head>.
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
sources | string | no | — | The name of one or many JavaScript files in the javascripts folder, minus the .js extension. Pass a full URL to access an external JavaScript file. Can also be called with the source argument. |
type | string | no | text/javascript | The type attribute for the script tag. |
head | boolean | no | false | Set to true to place the output in the head area of the HTML page instead of the default behavior (which is to place the output where the function is called from). |
delim | string | no | , | The delimiter to use for the list of JavaScript files. |
encode | boolean | no | true | Encode URL parameters using EncodeForURL(). Please note that this does not make the string safe for placement in HTML attributes, for that you need to wrap the result in EncodeForHtmlAttribute() or use linkTo(), startFormTag() etc instead. |
Examples
Section titled “Examples”<!--- View Code --->
<head>
<!--- Includes `public/javascripts/main.js` --->
#javaScriptIncludeTag("main")#
<!--- Includes `publicjavascripts/blog.js` and `public/javascripts/accordion.js` --->
#javaScriptIncludeTag("blog,accordion")#
<!--- Includes external JavaScript file --->
#javaScriptIncludeTag("https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js")#
</head>
<body>
<!--- Will still appear in the `head` --->
#javaScriptIncludeTag(source="tabs", head=true, type="text/javascript")#
</body>