More in this section

Forums / Developing with Sitefinity / Combining Source and Author meta fields to make a link

Combining Source and Author meta fields to make a link

5 posts, 0 answered
  1. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    18 Jun 2008
    Link to this post
    Is there a way to comine the URL from a source metafield together with the text in an Author metafield so that a hyperlink can be generated that will link to the source, but have the author as text? I can't seem to find a way to do this...

    thanks!
  2. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    19 Jun 2008
    Link to this post
    Hello SelArom,

    I suppose you want to customize SingleNews control. In this case refer to the following thread that explains how to extend SingleNews control.

    Please, describe in details if there is some misunderstanding.

    Greetings,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    19 Jun 2008
    Link to this post
    wait that's not going to work because i'm using a pluggable module based on the content view. would I extend the content view instead? how would this be done?
  4. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    19 Jun 2008
    Link to this post
    woooooot i figured it out! my module is a KnowledgeBase module, derived from genericcontent and I'm using the display modes so I had to extend that class, not the singlenews. I also didn't have any way to determine what mode its is so I had to use the obsolete displaymode, is there a newer construct for this? anyway here's my code, it totally works!

    i hardcoded the metatag that i needed but you get the idea:

    using System;  
    using System.Collections.Generic;  
    using System.Text;  
    using System.Web.UI;  
    using System.Web.UI.WebControls;  
    using Telerik.Cms.Engine;  
    using Telerik.Cms.Engine.WebControls;  
     
    namespace McAllen.Net.KnowledgeBase.WebControls  
    {  
        class KnowledgeBaseView : ContentView  
        {  
              
            public override string ProviderName  
            {  
                get 
                {  
                    return "KnowledgeBase";  
                }  
                set 
                {  
                    base.ProviderName = value;  
                }  
            }  
     
            public DisplayModes CurrentMode  
            {  
                get { return this.displayModeImpl; }  
            }  
     
            protected override void CreateChildControls()  
            {  
                base.CreateChildControls();  
     
                if (this.CurrentMode == DisplayModes.SingleItem)  
                {  
                    IContent cnt = base.Manager.GetContent(base.SelectedItemId);  
     
                    foreach (IMetaInfo info in base.Manager.MetaKeys.Values)  
                    {  
                        if (info.Key == "Author")  
                        {  
                            object metaData = cnt.GetMetaData(info.Key);  
                            HyperLink lnk = this.SingleContainer.FindControl(info.Key) as HyperLink;  
     
                            if (metaData != null)  
                            {  
                                if (cnt.GetMetaData("AuthorLink") != null)  
                                {  
                                    lnk.NavigateUrl = cnt.GetMetaData("AuthorLink").ToString();  
                                }  
                                lnk.Text = cnt.GetMetaData("Author").ToString();  
                            }  
                        }  
                    }  
                }  
            }  
        }  
    }  
     

    make sure that all of your entries have this metadata entry saved tho, because for the longest time it didn't work, kept returning null for the getmetadata("authorlink"), I couldn't figure out why, it drove me crazy but it turns out that the problem was that not all of the entires had been saved with that metadata. They can probably be blank, but I'm guessing that the entry has to actually exist for each entry...

    anyway hope this is helpful to someone!

    If anyone is interested in the kb module, I'd be happy to share the code on that too
  5. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    24 Jun 2008
    Link to this post
    Hi Josh,

    I can suggest an optimized version of your solution:

    using Telerik.Cms.Engine; 
    using Telerik.Cms.Engine.WebControls; 
     
    namespace McAllen.Net.KnowledgeBase.WebControls 
        class KnowledgeBaseView : ContentView 
        { 
            protected override string GetDefaultContentProvider() 
            { 
                return "KnowledgeBase"
            } 
     
            protected override void SetItemMetadata(Control itemContainer, IContent contentItem) 
            { 
                base.SetItemMetadata(itemContainer, contentItem); 
     
                if (this.itemId != Guid.Empty) 
                { 
                    object metaData = contentItem.GetMetaData("Author"); 
                    HyperLink lnk = itemContainer.FindControl("Author"as HyperLink; 
     
                    if (metaData != null && lnk != null
                    { 
                        lnk.Text = metaData.ToString(); 
     
                        if (contentItem.GetMetaData("AuthorLink") != null
                        { 
                            lnk.NavigateUrl = contentItem.GetMetaData("AuthorLink").ToString(); 
                        } 
                    } 
                } 
            } 
        } 

    Also, here is a reference to a KB article that describes how to extend ContentView control.

    Hope the information is helpful for you.

    Best wishes,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Register for webinar
5 posts, 0 answered