Help with custom tag output
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
>
var blogPost = App.WorkWith().BlogPosts().Get().First();
var tags = blogPost.GetValue("Tags");
TaxonRepeater.DataSource = tags;
TaxonRepeater.DataBind();
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);
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
>