Try our conversational search powered by Generative AI!

How to change the rendering of ContentArea

Vote:
 

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!

#116337
Jan 28, 2015 17:07
Vote:
 

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));
#116340
Jan 28, 2015 19:20
Vote:
 

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.

#116372
Jan 29, 2015 10:28
Vote:
 

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);
        }
#116404
Jan 29, 2015 16:33
Vote:
 

Tested with EPiServer 8.0.0
Still cannot hit the breakpoint

#117935
Feb 24, 2015 16:29
Vote:
 

Btw, are you MVC or Webforms?

#117936
Feb 24, 2015 16:32
Vote:
 

MVC

#117953
Feb 25, 2015 10:03
Vote:
 

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.

#206330
Aug 14, 2019 21:33
Vote:
 

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:

https://github.com/valdisiljuconoks/MvcAreasForEPiServer/blob/master/tests/AreasResearch/Business/Rendering/AlloyContentAreaRenderer.cs

and the requisite Initalization module:

https://github.com/valdisiljuconoks/MvcAreasForEPiServer/blob/master/tests/AreasResearch/Business/Initialization/DependencyResolverInitialization.cs

/Jake

#206426
Aug 20, 2019 21:57
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.