7

I have overwritten Tridion.ContentDelivery.Web.UI.ComponentLink to customize the link resolution.

public class ComponentLink : Tridion.ContentDelivery.Web.UI.ComponentLink
    {
        /// <summary>
        /// Overwritten render method to resolve links of News pages
        /// </summary>
        /// <param name="writer"></param>
        protected override void Render(HtmlTextWriter writer)
        {
            using (Tridion.ContentDelivery.Web.Linking.ComponentLink compLink = new Tridion.ContentDelivery.Web.Linking.ComponentLink(new Tridion.ContentDelivery.Web.Utilities.TcmUri(ComponentUri).PublicationId))
            {
                Tridion.ContentDelivery.Web.Linking.Link link = compLink.GetLink(PageUri, ComponentUri, TemplateUri, LinkAttributes, "", TextOnFail, AddAnchor);
                if (!link.IsResolved)
                {
                    Utility.LogEvent("Within First Condition");


                        if (Utility.IsNewsComponent(ComponentUri))
                        {
                            string linkString = string.Empty;
                            string newsBaseURL = ConfigurationManager.AppSettings["NewsBaseURL"].ToString();

                            int firstindex = ComponentUri.IndexOf('-', 0) + 1;
                            string componentid = ComponentUri.Substring(firstindex, ComponentUri.Length - (firstindex));

                            if (string.IsNullOrEmpty(LinkText))
                            {
                                linkString = string.Format(@" <a target=""_self"" title=""Read more here"" href=""{0}?id={1}"" class=""labelledIcon iconRight hidden-xs""> 
                                                                              Read more here", newsBaseURL, componentid);
                                LinkText = string.Format(@"<span class=""icon-arrow_right""></span>");
                            }
                            else
                            {
                                linkString = string.Format(@" <a href=""{0}?id={1}"" target=""_self"" >", newsBaseURL, componentid);
                            }

                            writer.Write(linkString);
                            writer.Write(LinkText);
                            this.RenderChildren(writer);
                            writer.Write("</a>");
                        }

                        else 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>");
                }
            }
        }
    }

Then I am trying to register the new DLL in web.config as:

Old entry:

<add tagPrefix="tridion" namespace="Tridion.ContentDelivery.Web.UI" assembly="Tridion.ContentDelivery" />

New entry

<add tagPrefix="tridion" namespace="Tridion.Extensions.ContentDelivery.Web.UI" assembly="TorkCustomLinkResolver" />

But doing this disables some of the existing functionalist that are based on other classes of Tridion.ContentDelivery.Web.UI.

like ComponentPresentation.

Please advice the correct procedure to use the extended Tridion.ContentDelivery.Web.UI.ComponentLink class.

2
  • Looks nice Vinod, but what are you trying to achieve ? If its only to add styling to the links then I think this approach is wrong. What is you have another template and you want other stylings ? What are you gone do then ?
    – user219
    Commented Nov 18, 2014 at 7:31
  • Hay Jarnohenneman... I do not have any other approach as such at present other than extending ComponentLink class for resolving the dynamic components for the above said scenario. Could you please suggest if you have. Commented Nov 25, 2014 at 10:24

2 Answers 2

7

What you can do is create new classes for the 'missing' functionality from the original Tridion.ContentDelivery.Web.UI assembly

you just need to create the class that inherits from the base class

public class ComponentPresentation : Tridion.ContentDelivery.Web.UI.ComponentPresentation
{
}

and if you don't override anything, you'll have this available in your assembly, with the exact same functionality as the original tridion assembly.

2
  • @ Frank: in this case, componentpresentation class refers to base componentresolver class to resolve any component. But I need it to refer my componentresolver class. That's the problem using above approach. Commented Nov 15, 2014 at 17:35
  • @Peter:due to the reason stated above. All the class internally calling componentresolver would call the base version only. And our class would not be called even when we the use tcdl Commented Nov 15, 2014 at 18:30
6

Alternatively, you could choose a different prefix for your custom functionality. It will be more obvious that it's your code and thus less confusing and easier to troubleshoot.

If you use TCDL for your links, you can create a tag handler that transforms tcdl:ComponentLink to your prefix instead of "tridion". If you are instead outputting tridion:ComponentLink in your templates directly, you would need to update your templates to use the new prefix.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.