Documentation > CMS Template API Library > Asset > GetLink(Boolean,ProtocolType)

GetLink

Renders a link to the asset based on the current context. Upon publishing, it will return the link to the published page. Upon previewing, it will return the cms preview link to the page. Defaults to LinkType.Default for the link type. Defaults to "output" for the layout. If this is a preview and a preview template exists, it will use that for a default.

public System.String GetLink(Boolean,ProtocolType)


Returns

The link to the asset

Parameters

NameDescriptionType
addDomain Optional: If true add HostName for current publishing package to link. Defaults to false. Must be in OutputContext (output template or filename or url template) and publishing. No effect in Preview. System.Boolean
protocolType Optional: If addDomain is true, determines if the protocol should be added and whether to use http or https. No effect in Preview.indexer. Defaults to http. CrownPeak.CMSAPI.ProtocolType

Code Example

C#

Sample:
<% Asset boardAsset = Asset.Load("/Site/About Us/Board of Directors"); %>
<a href="<%= boardAsset.GetLink() %>"><%= boardAsset.Label %></a><br />
/// <% Asset boardAsset = Asset.Load("/Site/About Us/Board of Directors"); %>
<a href="<%= boardAsset.GetLink(addDomain:true,protocolType:ProtocolType.Https) %>"><%= boardAsset.Label %></a><br />   

Connect with Crownpeak