Documentation > Services API > ServicesOutput > RenderCSSLink(Asset,String,String,String,OutputContext)
RenderCSSLink
For creating links to CSS assets. Accepts an asset and renders a link to it as an HTML link element. Use as a convenience function when building wrapper templates and anywhere you need to load a css asset in output.
public System.String RenderCSSLink(Asset,String,String,String,OutputContext)
Returns
String containing HTML code for loading a CSS Asset.
Parameters
Name | Description | Type |
---|---|---|
cssAsset | The CMS Asset that contains the CSS code. | CrownPeak.CMSAPI.Asset |
mediaType | Optional mediatype. | System.String |
cssIdAttribute | Optional html ID attribute for css link. | System.String |
qString | Optional query string appended to css link on publishing link. | System.String |
context | Optional current OutputContext for checking the publishing status. | CrownPeak.CMSAPI.OutputContext |
Code Example
C#
Sample:
Out.WriteLine(ServicesOutput.RenderCSSLink(cssAsset, context: context)); /*returns and outputs: <link rel="stylesheet" type="text/css" href="[[cssAsset publishing path or cms path]]?" */ Asset cssAsset = Asset.Load(asset["css_Asset"]); if (cssAsset.IsLoaded) { Out.WriteLine( ServicesOutput.RenderCSSLink(cssAsset, mediaType: "print", cssIdAttribute: "myCssIdAttribute", qString: "myQString", context) ); } /*returns and outputs: <link rel="stylesheet" type="text/css" href="[[cssAsset publishing path or cms path]]?myQString" media="print" id="myCssIdAttribute" /> assuming both the css and the containing/wrapping assets are in publishing states.*/