A critical vulnerability was discovered in React Server Components (Next.js). Our systems remain protected but we advise to update packages to newest version. Learn More

Per Magne Skuseth
Nov 14, 2014
  6195
(6 votes)

Content Providers 101 – Part III: Finishing Touches

This is the final part of my blog post series Content Providers 101. Make sure you’ve read Part I and Part II before reading this!

The provider is now almost complete, we just need to put the finishing touches to it.

Searching: In the component, there is a search box. In order to get it to return actual items, a search provider is needed

[SearchProvider]
public class AttendeeSearchProvider : ContentSearchProviderBase<Attendee, ContentType>
{
    private readonly AttendeeProvider _attendeeProvider;
 
    public AttendeeSearchProvider(LocalizationService localizationService, SiteDefinitionResolver siteDefinitionResolver,
        IContentTypeRepository<ContentType> contentTypeRepository, IContentProviderManager contentProviderManager)
        : base(localizationService, siteDefinitionResolver, contentTypeRepository)
    {
        _attendeeProvider = contentProviderManager.GetProvider(AttendeeProvider.Key) as AttendeeProvider;
    }
 
    public override IEnumerable<SearchResult> Search(Query query)
    {
        IEnumerable<Person> people = PersonService.Search(query.SearchQuery);
        foreach (var attendee in people.Select(x => _attendeeProvider.ConvertToAttendee(x)))
        {
            yield return this.CreateSearchResult(attendee);
        }
    }
 
    public override string Area { get { return AttendeeProvider.Key; } }
    public override string Category { get { return AttendeeProvider.Key; } }
    protected override string IconCssClass { get { return "attendee-search-icon"; } }
}

To connect the search provider to the attendee component, override and match the SearchArea property on the repository descriptor (AttendeeRepositoryDescriptor) to the Area property in the search provider:

public override string SearchArea { get { return AttendeeProvider.Key; } }

 

The search provider will work for both the component and for the global navigation search

attendee_search

 

Speaking of search, if you are using EPiServer Find, the attendee data will automatically be indexed to Find when when running the content indexing job. This happens as Find will traverse the entire content tree and index all the IContent there is, including the “attendees” content folder beneath the root node.
This means that you can get attendees as a part of UnifiedSearch with just a single line of code:

SearchClient.Instance.Conventions.UnifiedSearchRegistry.Add(typeof(Attendee));

 

Preview: EPiServer offers a great on-page editing experience, so we should enable this for attendee content as well.
The preview controller in Alloy only works with BlockData, but can easily modified to work with attendees as well:

[TemplateDescriptor(
    Inherited = true, TemplateTypeCategory = TemplateTypeCategories.MvcController, 
    Tags = new[] { RenderingTags.Preview, RenderingTags.Edit },
    AvailableWithoutTag = false, ModelType = typeof(BlockData))]
[TemplateDescriptor(
    TemplateTypeCategory = TemplateTypeCategories.MvcController, 
    Tags = new[] { RenderingTags.Preview, RenderingTags.Edit },
    AvailableWithoutTag = false, ModelType = typeof(Attendee))]
[VisitorGroupImpersonation]
public class PreviewController : ActionControllerBase, IModifyLayout


What I’ve done is to remove the IRenderTemplate<BlockData> interface, and instead specified the model type in the TemplateDescriptor. Since TemplateDescriptors allows multiple attributes, I’ve added one for attendees as well.

 

Change context: When double-clicking blocks or media in the assets pane, the clicked item will be loaded and displayed. In order to get the same behavior for our attendees, we need to specify this in the AttendeeRepositoryDescriptor:

public bool ChangeContextOnItemSelection{get{return true;}}


The HierarchialList component will look for a matching property. If it does not exists or is set to false, the context will not change when double clicking the item, and you will have to use the edit button from the drop down menu in order to load and see the item.

 

Custom icon: In the assets pane, the icon that is being used for attendees is the standard content icon. In order to get one step closer to UX nirvana, a more descriptive icon should be used instead. This is done  by creating a UIDescriptor:

[UIDescriptorRegistration]
public class AttendeeUiDescriptor : UIDescriptor<Attendee>
{
    public AttendeeUiDescriptor()
    {
        IconClass = "epi-iconUser";
    }
}


attendee_with_icon

Tip: See lists of icons and corresponding css class names at ux.episerver.com

 

Try it!

Want to try it out? Get the source code here
Also: A big thanks to Linus Ekström for being super helpful!

Nov 14, 2014

Comments

Emanuel Herteliu
Emanuel Herteliu Jul 12, 2017 11:42 AM

Thank you for posting this!

Tried your example modifying the Attendee class to inherit PageData so the results get displayed in a ContentPage container as pages.

The issue is we can't get the ContentProviderResult using DataFactory.FindPagesWithCriteria.

Snippet

ContentRepository.GetChildren<>Attendee>(page.PageLink); -> works ('page' is the container ContentPage mentioned earlier)

Snippet
PropertyCriteriaCollection crits = new PropertyCriteriaCollection();
       PropertyCriteria crit = new PropertyCriteria();
       crit.Name = "EPI:MultipleSearch";
       crit.Value = "attendees";
DataFactory.Instance.FindPagesWithCriteria(page.PageLink, crits); -> won't work

Also tried crit.Value = "*"

In the initialization module did Snippet
searchClient.Conventions.UnifiedSearchRegistry.Add(typeof(Attendee));

Any idea why using GetChildren of ContentRepository works but not FindPagesWithCriteria....?

Also.... a second question: the pages returned by the ContentProvider get displayed in the tree structure in CMS but when clicking show 'All Properties' it will load forever...
any idea why?

The reason why we are trying to implement the ContentProvider is because we have entities from an external Database that we want to route to an Episerver ContentPage and trying a partial router didn't work
because our entities don't inherit from IContent. That's why we're trying to implement the custom ContentProvider: to bring the entities from the external DB as Episerver pages which
we will route.

Please login to comment.
Latest blogs
A day in the life of an Optimizely OMVP: Unlock the Power of Unified Search: Introducing Custom Data Management for Optimizely Graph

Bring all your data together in one searchable experience The Challenge: Siloed Data, Fragmented Search Every organisation has data spread across...

Graham Carr | Jan 16, 2026

Alt text is retrieved for images imported from CMP-DAM in Optimizely CMS 12.

Introduction Although image alt text is stored as metadata in CMP/DAM, it is not automatically rendered in browser HTML. This document outlines the...

Deepmala S | Jan 16, 2026

Announcing Stott Security Version 4.0

January 2026 marks the release of Stott Security v4, a significant update to the popular web security add-on for Optimizely CMS 12, with more than...

Mark Stott | Jan 16, 2026

Optimizely Graph Best Practices - Content Modelling and Querying

Introduction With the Mando Group team having worked extensively with Optimizely Graph over the last 12+ months, we have uncovered a number of best...

Jon Williams | Jan 16, 2026