Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

Load Blocks in Fragments

Vote:
 

I need to display a block on a page. For the very first time when page load, only 6 blocks should be displayed by default. And there is a "Load More" button on that page, once user click on this button the next 6 more blocks should be displayed and so on.  Requirement

#147851
Apr 26, 2016 15:23
Vote:
 

Option 1 is to take control of the rendering of content area yourself. You can use the ContentArea.Items collection for this:

@{
    var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>();
    if (page != null && page.ContentArea != null && page.ContentArea.FilteredItems.Any())
    {
        foreach (var contentItem in page.ContentArea.FilteredItems)
        {
            var item = contentLoader.Get<INSERT CONTENT TYPE>(contentItem.ContentLink);           
 //print your properties...
        }
    }
}

Option 2 is to use javascript to simply hide the ones you don't want to show. And then let button trigger to show 6 more. Easier but might be a performance issue if you have really many. I would go for this one normally since it's rare you have enough blocks that this would actually be a real problem.

#147857
Apr 26, 2016 17:20
Vote:
 

Thanks Daniel!

But I getting this error:

The name 'Locate' does not exist in the current contex

Is there any namespace required for Locate? What Is that?

Thanks!

#147883
Edited, Apr 27, 2016 11:00
Vote:
 

Locate is a shortcut property that is available on some classes that is used to fetch instances of services. You can also use the ServiceLocator for that directly as well (like above) and that is in the 

EPiServer.ServiceLocation

namespace. 

#147885
Edited, Apr 27, 2016 11:11
* 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.