Documentation > Services API > ServicesOutput > RenderScriptLink(String,String,String,OutputContext)


For creating links to JavaScript assets. Loads an asset by path 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(String,String,String,OutputContext)


String containing the HTML code for loading a script file


scriptPath Path of the Script Asset to Load System.String
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



             Out.WriteLine( ServicesOutput.RenderScriptLink(scriptPath,"text/javascript",context) );
             //returns: <script type="text/javascript" src="/js/scripts.js?"></script>   assuming /_assets/ are published to the site root on publishing properties
             string scriptPath = "/SAMPLE Pharmaceutical/_Assets/js/scripts.js";
             Out.WriteLine( ServicesOutput.RenderScriptLink(scriptPath,"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 

Connect with Crownpeak