Widget code-behind for single item templates
Hi,
I've been using the following to add code-behind to built in widgets for list items which works great
www.sitefinity.com/.../howto-guide-add-code-behind-to-a-sitefinity-widget-template
I'd like to do the same for single items, does anyone know how I can access the data items in the code-behind?
Hi David,
The procedure would be similar for a single item, but in this case you will work on the Full Blog Post item template by going to Design>>Widget Templates.
Another easy way to get the current item would consist on extending the Blog Posts widget (or creating a new one). It is easily possible by creating a class which inherits from BlogPostView in Visual Studio as shown on this video.
The code may look similar to this:
public
class
CustomBlogPostItem : BlogPostView
protected
override
void
CreateChildControls()
base
.CreateChildControls();
var view =
this
.CurrentView;
if
(view.ViewType.FullName ==
"Telerik.Sitefinity.Modules.Blogs.Web.UI.Public.DetailPostView"
)
var item =
this
.DetailItem;