Help with custom tag output

Posted by Community Admin on 04-Aug-2018 20:22

Help with custom tag output

All Replies

Posted by Community Admin on 05-Aug-2011 00:00

Let me start by saying I have read through just about every post I can find on this subject and I have yet to find what I would consider a helpful answer from support.  Just about every thread I have found on this subject has made the statement to just make a usercontrol and bind the output to a repeater or treeview and then to use the extension method GetValue("Tags"). 

It would be helpful to see an actual example of the correct way to do this.

All I want to do is change the way tags are output for a blog post.  I do not want to filter posts by tags.  I want to grab all tags associated with one particular blog post and output them in a comma delimited fashion instead of the list approach that is used by default.

Here is what I have so far.
I have a usercontrol that i am trying to do a simple test on.  This control has a repeater that I want to bind the tags to.  One problem I am finding is I do not know what the filed is called.  I am trying to use tags, title, name, tag and all give me an error that such a property does not exist.  Below is how it currently looks

<asp:Repeater ID="TaxonRepeater" runat="server">
    <ItemTemplate>
     <%# Eval("Tag") %>,
    </ItemTemplate>
</asp:Repeater>


The code behind is pretty simple right now as I just wanted to make sure I was actually grabbing a blog post. I am not sure what the correct way to do this when the user control will be inside of the blogpost list template is.

var blogPost = App.WorkWith().BlogPosts().Get().First();
            var tags = blogPost.GetValue("Tags");
 
            TaxonRepeater.DataSource = tags;
            TaxonRepeater.DataBind();

I do not get any output from this.  Is this even remotely close to how I should be attempting this?

EDIT:  After tracing results I am seeing that my variable "tags" outputs Telerik.OpenAccess.TrackedList`1[System.Guid]

Also: I know I could handle this with CSS by floated the list elements, but I am trying to learn how to use the API.

Posted by Community Admin on 05-Aug-2011 00:00

I just found a post that had something that looks to be getting me closer.  I still need to work on it to get it bound to my repeater, but I am now seeing the actual names of the tags output in trace.  Here is the updated code that I am playing with and this was taken out of context of this thread

var tags = (Telerik.OpenAccess.TrackedList<System.Guid>)blogPost.GetValue("Tags");
TaxonomyManager tm = new TaxonomyManager();
 
            foreach (Guid g in tags)
            
                FlatTaxon ft = (FlatTaxon)tm.GetTaxon(g);
                if (ft != null)
                    Trace.Warn("Tags Output", ft.Name);
            

Posted by Community Admin on 08-Aug-2011 00:00

Hello Stacey,

Using the GetValue("Tags")will indeed return a LIst of the tag IDs persisted in that field, howeve, as you have properly pointed out you can then loop through that list and get the corresponding tag using the TaxonomyManager. Please refer to the following sample:

var blogPost = App.WorkWith().BlogPosts().Get().First();
           var tags = (TrackedList<Guid>)blogPost.GetValue("Tags");
           var manager = TaxonomyManager.GetManager();
           var myTags = new List<ITaxon>();
           foreach (Guid tg in tags)
           
               myTags.Add(manager.GetTaxon(tg)); 
           
           TaxonRepeater.DataSource = myTags;
           TaxonRepeater.DataBind();

<div>
    <asp:Repeater ID="TaxonRepeater" runat="server">
    <ItemTemplate>
     <%# Eval("Title") %>,
    </ItemTemplate>
</asp:Repeater>
 
    </div>


Regards,
Boyan Barnev
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed