Created
August 20, 2012 21:25
-
-
Save willprice76/3408047 to your computer and use it in GitHub Desktop.
Tridion Extended Component Link Control Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.ComponentModel; | |
using Tridion.ContentDelivery.Web.Utilities; | |
namespace Tridion.Extensions.ContentDelivery.Web.UI | |
{ | |
/// <summary> | |
/// Custom ComponentLink class, to replace the Tridion.ContentDelivery.Web.UI.ComponentLink | |
/// class with an added property to set query string parameters | |
/// </summary> | |
public class ComponentLink : Tridion.ContentDelivery.Web.UI.ComponentLink | |
{ | |
// New Properties | |
[Category("Appearance"), Bindable(true), DefaultValue("")] | |
public string Parameters { get; set; } | |
protected override void Render(System.Web.UI.HtmlTextWriter writer) | |
{ | |
using (Tridion.ContentDelivery.Web.Linking.ComponentLink compLink = | |
new Tridion.ContentDelivery.Web.Linking.ComponentLink(new TcmUri(ComponentUri).PublicationId)) | |
{ | |
Tridion.ContentDelivery.Web.Linking.Link link = | |
compLink.GetLink(PageUri, ComponentUri, TemplateUri, LinkAttributes, "", TextOnFail, AddAnchor); | |
link.Parameters = Parameters; | |
if (!link.IsResolved) | |
{ | |
if (TextOnFail) | |
{ | |
writer.Write(LinkText); | |
this.RenderChildren(writer); | |
} | |
} | |
else | |
{ | |
string linkString = link.ToString(); | |
int index = linkString.IndexOf("</a>"); | |
if (index > 0) | |
{ | |
linkString = linkString.Substring(0, index); | |
} | |
writer.Write(linkString); | |
writer.Write(LinkText); | |
this.RenderChildren(writer); | |
writer.Write("</a>"); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment