Skip to content

View Helpers

javaScriptIncludeTag()

javaScriptIncludeTag() — returns string

Available in: controller Category: Asset Functions

Returns a script tag for a JavaScript file (or several) based on the supplied arguments.

NameTypeRequiredDefaultDescription
sourcesstringnoThe 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.
typestringnotext/javascriptThe type attribute for the script tag.
headbooleannofalseSet 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).
delimstringno,The delimiter to use for the list of JavaScript files.
encodebooleannotrueUse this argument to decide whether the output of the function should be encoded in order to prevent Cross Site Scripting (XSS) attacks. Set it to true to encode all relevant output for the specific HTML element in question (e.g. tag content, attribute values, and URLs). For HTML elements that have both tag content and attribute values you can set this argument to attributes to only encode attribute values and not tag content.
<!--- View Code --->
<head>
    <!--- Includes `javascripts/main.js` --->
    #javaScriptIncludeTag("main")#

    <!--- Includes `javascripts/blog.js` and `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)#
</body>