Documentation > Services API > ServicesOutput > RenderScriptLink(Int32,String,String,OutputContext)
RenderScriptLink
For creating links to JavaScript assets. Loads an asset by Id and 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(Int32,String,String,OutputContext)
Returns
String containing the HTML code for loading a script file
Parameters
| Name | Description | Type |
|---|---|---|
| scriptId | ID of the Script Asset to Load | System.Int32 |
| 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.Id, context: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("/SAMPLE Pharmaceutical/_Assets/js/scripts.js");
Out.WriteLine( ServicesOutput.RenderScriptLink(scriptAsset.Id,"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