Single Generic Content item widget
Hi,
Is it possible to configure the standard Generic Content List widget to display a single generic content item in detail view? Or would I have to create my own widget for this?
Alternatively, I'm trying to create some content (a list) that can be added to any page, but updated centrally. A generic content item seemed perfect for this, but if there's a better idea please let me know.
Thanks,
Neil.
Hello Neil,
There is a way to do this, but you should override CreateChildControls method of ContentView control.
protected
override
void
CreateChildControls()
this
.Controls.Clear();
ResolveDetailItem();
var currentView =
this
.DetermineCurrentViewName();
var manager = NewsManager.GetManager();
var itm = manager.GetItem(
typeof
(NewsItem),
new
Guid(
"a2f41c08-2d37-45db-8a9d-bbfdb5076dce"
));
var c = itm
as
IContent;
this
.DetailItem = c;
this
.LoadView(currentView);
Where do you put this code?
Hi Damian,
Create a custom class library and inherit from ContentView. Then you need to register the control from Sitefinity >>Administration >>Settings >> Toolboxes
Regards,
Ivan Dimitrov
the Telerik team
Thanks! That worked.
A follow up question: Is there a way to let the admin users pick a generic content to display in this control without hardcoding a guid in the control itself? Maybe have a generic content picker or let users find out the guid of their generic content and paste it into some kind of property on this widget?
Hi Damian,
You can expose a public property of your custom control or some kind of ControlDesigner.
Best wishes,
Ivan Dimitrov
the Telerik team
Thanks again! The public property works great.
Is there any way to hide the inherited properties like AccessKey, BackColor, etc so that admin users wouldn't care about when editing a widget?
Hi Damian,
Override the properties and add [Browsable(false)] attribute to them.
Kind regards,
Ivan Dimitrov
the Telerik team
Perfect. Thanks so much!
Hi Damian,
I never got round to solving this myself - any chance you can share the source for your widget?
Cheers,
Neil.
My code looks something like this:
01.
using
System;
02.
using
System.Collections.Generic;
03.
using
System.Linq;
04.
05.
namespace
SitefinityWebApp.Classes
06.
07.
public
class
GenericContentItem : System.Web.UI.WebControls.CompositeControl, Telerik.Sitefinity.Web.UI.ICustomWidgetVisualization
08.
09.
public
string
ContentTitle
get
;
set
;
10.
11.
protected
override
void
CreateChildControls()
12.
13.
if
(ContentTitle ==
null
)
14.
return
;
15.
16.
var manager =
new
Telerik.Sitefinity.Modules.GenericContent.ContentManager();
17.
var content = manager.GetContent().ToList().FirstOrDefault(item => item.Title.Value.ToLower() ==
this
.ContentTitle.ToLower());
18.
19.
if
(content !=
null
)
20.
this
.Controls.Add(
new
System.Web.UI.LiteralControl(content.Content.Value));
21.
22.
23.
#region ICustomWidgetVisualization Members
24.
string
Telerik.Sitefinity.Web.UI.ICustomWidgetVisualization.EmptyLinkText
get
return
string
.Empty;
25.
bool
Telerik.Sitefinity.Web.UI.ICustomWidgetVisualization.IsEmpty
get
return
false
;
26.
#endregion
27.
28.
Hi Telerik,
so longer I work with Sitefinity 4, I can not shake the feeling that this is an unfinished version. How do I explain my customer that they can not work with this version because some things like generic content not work as that are accustomed from version 3.7 where they were right? The customer does not need a list of generic content, but a simple sharing of a single generic content items. Customer paid for a product that is not functioning as it should be and was before and now have to pay the work that I do make it working as before? Really frustrated! This way I can forget about the other contracts !!!
Greatings,
Pavol Kokinda
Hello Pavol,
Shared content will be available for Q1 release. Please check our roadmap to see all other new features that we will have.
Best wishes,
Ivan Dimitrov
the Telerik team