Afroz
Afroz

Reputation: 1102

Added a Field to WeBlog Entry template, trying to get the field in Category.ascx.cs

I have followed the steps in the following link Template Settings and created custom templates for Entry, Comment and Category. To the Custom Entry Template, I have added an additional field. I have a requirement to display it in the Categories.ascx. I am able to override the Categories.ascx but I am unable to get the value of the added field using WeBlog's API. Here's the code that I am using. But the issue is that the Class EntryItem doesn't have the additional field that I have added. Is there a way to read this field using WeBlog API?

EntryItem[] blogEntries = ManagerFactory.EntryManagerInstance.GetBlogEntries();

Upvotes: 0

Views: 63

Answers (2)

Ian Graham
Ian Graham

Reputation: 3216

EntryItem inherits from CustomItem I believe, so you can use the InnerItem Property to get access to the actual Item. Your field should then be available like this:

 entryItem.InnerITem["YouField"];

You can use a field renderer in the Categories.ascx file to display the value of you field and use data binding to get the item assigned to the field renderer.

 <sc:FieldRenderer ID="FieldRenderer1" runat="server" FieldName="YourField"  item='<%# entryItem.innerItem %>'/>

Upvotes: 1

Mark Ursino
Mark Ursino

Reputation: 31435

In Categories.ascx you can add this code to render the new field on the front-end:

<sc:FieldRenderer FieldName="Your New Field Name" ID="frNewField" runat="server" />

Then in the C# code-behind, add this code to data bind the front-end field renderer to the entry item's underlying Sitecore item:

frNewField.Item = entryItem.InnerItem;

Upvotes: 0

Related Questions