Documentation > Services API > ServicesOutput > RenderScriptLink(Asset,String,String,OutputContext)
RenderScriptLink
For creating links to JavaScript assets. Given an asset, renders a link to it in an HTML script element. Use as a convenience function for creating links to javascript assets.
public System.String RenderScriptLink(Asset,String,String,OutputContext)
Returns
String containing the HTML code for loading a script file
Parameters
| Name | Description | Type |
|---|---|---|
| scriptAsset | Script Asset to Load | CrownPeak.CMSAPI.Asset |
| scriptType | Optional script type; the default is text/javascript | System.String |
| qString | Optional query string appended to the Javascript link | System.String |
| context | Optional current OutputContext for checking the publishing status | CrownPeak.CMSAPI.OutputContext |
Code Example
C#
Sample:
Out.WriteLine( ServicesOutput.RenderScriptLink(scriptAsset,"text/javascript",context) );
//returns: <script type="text/javascript" src="/js/scripts.js?"></script> assuming /_assets/ are published to the site root on publishing properties
Asset scriptAsset = Asset.Load(asset["Script_Asset"]);
if(scriptAsset.IsLoaded)
{
Out.WriteLine( ServicesOutput.RenderScriptLink(scriptAsset,"text/javascript","SampleQString",context) );
}
//returns: <script type="text/javascript" src="/js/scripts.js?SampleQString"></script> assuming /_assets/ are published to the site root on publishing properties