Limiting rendering of content area items

Vote:
 

Hi,

is there a way to limit the number (e.g. max 10) of content area items to render without using a valdiation.

Thanks

#131825
Aug 06, 2015 11:09
Vote:
 

Hi,

Maybe you could register your own ContentArea renderer

 private static void ConfigureContainer(ConfigurationExpression container)
        {
            container.For<ContentAreaRenderer>().Use<AlloyContentAreaRenderer>();
        }


public class AlloyContentAreaRenderer : ContentAreaRenderer
    {
        protected override void RenderContentAreaItems(HtmlHelper htmlHelper, IEnumerable<ContentAreaItem> contentAreaItems)
        {
            var maxElements = htmlHelper.ViewContext.ViewData["maxElements"];
            if (maxElements != null)
            {
                contentAreaItems = contentAreaItems.Take((int)maxElements);
            }
            base.RenderContentAreaItems(htmlHelper, contentAreaItems);
        }
}

I didnt test this code.

#131826
Aug 06, 2015 11:51
Vote:
 

Would also think about editor side to prevent more items to be created inside content area if maximum items exceeded..

#131852
Aug 06, 2015 20:23
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.