Join us this Friday for AI in Action at the Virtual Happy Hour! This free virtual event is open to all—enroll now on Academy and don’t miss out.
Join us this Friday for AI in Action at the Virtual Happy Hour! This free virtual event is open to all—enroll now on Academy and don’t miss out.
Hi,
Inherit from EPiServer.Web.PropertyControls.PropertyContentAreaControl. Then override the CreateEditControls() method.
Register your control in Global.asax or in an initializable module:
PropertyControlClassFactory.Instance.RegisterClass( typeof(EPiServer.SpecializedProperties.PropertyContentArea), typeof(YourPropertyContentAreaControl));
Hi Johan,
I've created custom property PropertyContentAreaControl:
public class CustomPropertyContentAreaControl : PropertyContentAreaControl
And then created the initialization module:
[InitializableModule] [ModuleDependency(typeof(InitializationModule))] public class PropertyContentAreaControlInitModule : IInitializableModule { public void Initialize(InitializationEngine context) { if (context.HostType == HostType.WebApplication) { PropertyControlClassFactory.Instance.RegisterClass(typeof(PropertyContentArea), typeof(CustomPropertyContentAreaControl)); } } public void Preload(string[] parameters) { } public void Uninitialize(InitializationEngine context) { } }
I've set the break point in constructor and CreateEditControls() method of my CustomPropertyContentAreaControl, but I can never hit the break point.
I also tried to register the class in Global.asax instead of using initializable module:
public class EPiServerApplication : Global { protected void Application_Start() { AreaRegistration.RegisterAllAreas(); } public override void Init() { base.Init(); PropertyControlClassFactory.Instance.RegisterClass(typeof(PropertyContentArea), typeof(CustomPropertyContentAreaControl)); } }
Nothing seems to works. EPiServerErrors.log file is empty.
Weird, that should work. This is the default implementation of CreateEditControls():
public override void CreateEditControls() { ContentArea value = base.PropertyData.Value as ContentArea; if (value == null || value.IsEmpty) { this.Controls.Add(new LiteralControl(LocalizationService.Current.GetString("/edit/contentarea/empty"))); return; } HtmlGenericControl htmlGenericControl = new HtmlGenericControl("ul"); htmlGenericControl.Attributes["class"] = "epi-blockarea"; foreach (ContentAreaItem item in value.Items) { HtmlGenericControl htmlGenericControl1 = new HtmlGenericControl("li"); IContent content = item.GetContent(this.ContentRepository.Service); if (content == null) { htmlGenericControl1.Attributes["class"] = "epi-blockarea-missingblock"; htmlGenericControl1.InnerHtml = string.Format(LocalizationService.Current.GetString("/edit/contentarea/missingcontent"), item.ContentLink); } else { ContentType contentType = this.ContentTypeRepository.Service.Load(content.ContentTypeID); htmlGenericControl1.InnerText = string.Format("{0} ({1})", content.Name, contentType.LocalizedName); } htmlGenericControl.Controls.Add(htmlGenericControl1); } this.Controls.Add(htmlGenericControl); }
I realize this is an old thread, but I am unable to implement this in Episerver 11 using the examples above. I also never hit the breakpoints that Dejan tried, but I did hit a breakpoint in my initialization module that calls PropertyControlClassFactory.Instance.RegisterClass. Any guidiance on how to get this working would be greatly appreciated.
Hi,
This example looks to be Web Forms, so I don't you'll ever hit that break point if you're using MVC!
Without knowing exactly what you want to achieve, my guess is you'll want to create your own custom ContentAreaRenderer, inheriting the existing one and overriding a few methods.
There is an example that'll get you started here:
and the requisite Initalization module:
/Jake
Hi,
I would like to change how blocks are rendered in Content Area.
By default, we can only see the name of the block, but I would like to see the block type as well.
What's the best way to achieve this?
Can I create my own ContentAreaRenderer for this?
Any help would be greatly appreciated!