World is now on Opti ID! Learn more

Per Magne Skuseth
Nov 14, 2014
  3019
(0 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

Please login to comment.
Latest blogs
Make Global Assets Site- and Language-Aware at Indexing Time

I had a support case the other day with a question around search on global assets on a multisite. This is the result of that investigation. This co...

dada | Jun 26, 2025

The remote server returned an error: (400) Bad Request – when configuring Azure Storage for an older Optimizely CMS site

How to fix a strange issue that occurred when I moved editor-uploaded files for some old Optimizely CMS 11 solutions to Azure Storage.

Tomas Hensrud Gulla | Jun 26, 2025 |

Enable Opal AI for your Optimizely products

Learn how to enable Opal AI, and meet your infinite workforce.

Tomas Hensrud Gulla | Jun 25, 2025 |

Deploying to Optimizely Frontend Hosting: A Practical Guide

Optimizely Frontend Hosting is a cloud-based solution for deploying headless frontend applications - currently supporting only Next.js projects. It...

Szymon Uryga | Jun 25, 2025

World on Opti ID

We're excited to announce that world.optimizely.com is now integrated with Opti ID! What does this mean for you? New Users:  You can now log in wit...

Patrick Lam | Jun 22, 2025

Avoid Scandinavian Letters in File Names in Optimizely CMS

Discover how Scandinavian letters in file names can break media in Optimizely CMS—and learn a simple code fix to automatically sanitize uploads for...

Henning Sjørbotten | Jun 19, 2025 |