How to Configure Content Grid View Plugin in Optimizely/Episerver CMS

How to Configure Content Grid View Plugin in Optimizely/Episerver CMS

The plugin EPiserver.Labs.GridView allows you to create container pages similar to how buckets works in Sitecore CMS, and it has been a great tool when you have several children below a page. For instance, in a article listing, article detail pages scenario. When we first installed this package we were following an old documentation an seems like at the time of writing this post was properly updated. The documentation for the project can be found here and in this blog post we are going to show you how you can implement it using a real case scenario. So lets begin.

First, you have to install the nuget package using the nuget package console with this command:

Install-Package EPiServer.Labs.GridView

Or you can use the nuget package manager in visual studio.

Second, we will create the article detail page which will have only a title, teaser and related articles content area property. Pay special attention to the content area field which specifies that we are going to use the grid view option instead of the default view.

using EPiServer.Core;
using EPiServer.DataAbstraction;
using EPiServer.DataAnnotations;
using EPiServer.Labs.GridView.EditorDescriptors;
using EPiServer.Web;
using System.ComponentModel.DataAnnotations;

namespace Foundation.Features.Article.Pages.ArticleDetailPage
{
    [ContentType(DisplayName = "Article Detail Page",
        GUID = "EAACADF2-3E89-4117-ADEB-F8D43565D2F4",
        Description = "Allow content authors to create and display Article content on the site",
        GroupName = "Articles")]
    [AvailableContentTypes(Availability.Specific, Include = new[] { typeof(ArticleLandingPage.ArticleLandingPage), typeof(ArticleDetailPage) })]
    [ImageUrl("~/assets/icons/cms/pages/cms-icon-page-18.png")]
    public class ArticleDetailPage : PageData
    {
        [Required]
        [CultureSpecific]
        [Display(Name = "Heading Title", GroupName = "Content", Order = 100)]
        public virtual string HeadingTitle { get; set; }

        [Required]
        [CultureSpecific]
        [UIHint(UIHint.Textarea)]
        [Display(Name = "Teaser", GroupName = "Content", Order = 200)]
        public virtual string Teaser { get; set; }

        [CultureSpecific]
        [Display(Name = "Related Articles", Order = 300)]
        [AllowedTypes(typeof(ArticleDetailPage))]
        [UIHint(GridViewEditing.UIHint)] // Show grid view instead of default one
        [PropertyGridConfiguration] // Enable property grid configuration
        public virtual ContentArea RelatedArticles { get; set; }
    }
}

If you do not set both attributes, UIHint plus the Property Grid Configuration, you will see this screen to search for content, which is the default one and unfortunately does not work if you have hundreds of items below a page or folder.

Now, if you add those attributes, you will see the following screen which also has a way to search for content inside an item instead of clicking around the site to find a block or page.
We will then add the code for the article listing page which will have a heading property and a content area for articles following the same structure as the content area for related articles in the article detail page.
using EPiServer.Core;
using EPiServer.DataAbstraction;
using EPiServer.DataAnnotations;
using EPiServer.Labs.GridView.EditorDescriptors;
using System.ComponentModel.DataAnnotations;

namespace Foundation.Features.Article.Pages.ArticleLandingPage
{
    [ContentType(DisplayName = "Article Landing Page",
        GUID = "EAADAFF2-3E89-4117-ADEB-F8D43565D2F4",
        Description = "Article Landing for dates such as year and month",
        GroupName = "Articles")]
    [AvailableContentTypes(Availability.Specific, Include = new[] { typeof(ArticleLandingPage), typeof(ArticleDetailPage.ArticleDetailPage) })]
    [ImageUrl("~/assets/icons/cms/pages/cms-icon-page-20.png")]
    public class ArticleLandingPage : PageData
    {
        [Required]
        [CultureSpecific]
        [Display(Name = "Heading Title", GroupName = "Content", Order = 100)]
        public virtual string HeadingTitle { get; set; }

        [CultureSpecific]
        [Display(Name = "Articles", Order = 200)]
        [AllowedTypes(typeof(ArticleDetailPage.ArticleDetailPage))]
        [UIHint(GridViewEditing.UIHint)]
        [PropertyGridConfiguration]
        public virtual ContentArea Articles { get; set; }
    }
}

Now, you can configure this article listing page to be a container by pressing the convert to container button in the CMS editor interface.

By default a page has two view options. The on-page editing and all properties views.
But if you press the convert to container button, you will be able to see another type of view called children grid which will display all the pages or blocks below the page that you selected as container.

To activate the view you need to enable it using a view configuration which will specify which type will have the view enabled.

using EPiServer.Labs.GridView;
using EPiServer.ServiceLocation;
using EPiServer.Shell;

namespace Foundation.Features.Article.Pages.ArticleLandingPage
{
    [ServiceConfiguration(typeof(ViewConfiguration))]
    public class ArticleLandingPageViewConfiguration : SearchContentView<ArticleLandingPage>
    {
    }
}

And this is how the new children grid view looks.

If you want to configure how the different article detail pages are going to look you in this view, you can add a class specifying the different columns. An example of this code is displayed below with all the columns that you are seeing in the image above. You can also create your own custom fields as specified in the documentation of the project.

using EPiServer.Labs.GridView;
using EPiServer.Labs.GridView.GridConfiguration;
using EPiServer.Shell;

namespace Foundation.Features.Article.Pages.ArticleLandingPage
{
    [UIDescriptorRegistration]
    public class ArticleLandingPageViewUiDescriptor : ExtendedUIDescriptor<ArticleLandingPage>
    {
        public ArticleLandingPageViewUiDescriptor()
            : base(ContentTypeCssClassNames.Page)
        {
            DefaultView = SearchContentViewContentData.ViewKey;
            GridSettings = new GridSettings
            {
                Columns = new ColumnsListBuilder()
                    .WithContentName()
                    .WithContentStatus()
                    .WithContentTypeName()
                    .WithVisibleInMenu()
                    .WithCreatedBy()
                    .WithPublishDate()
                    .WithCurrentLanguageBranch()
                    .WithEdit()
                    .WithPreviewUrl()
                    .WithActionMenu()
                    .Build()
            };
        }
    }
}

Finally, you will also be able to identify container pages in the page content tree by the icon added to the page.

And that is it, You can now have a similar buckets feature inside Episerver/Optimizely CMS without too much effort. All credits to the Episerver Labs team. If you have any question let me know. I hope it will help someone and as always keep learning !!!

Written by:

Jorge Cardenas

Developer with several years of experience who is passionate about technology and how to solve problems through it.

View All Posts

Leave a Reply