Try our conversational search powered by Generative AI!

bpedwards
Nov 20, 2008
  4964
(0 votes)

Displaying plugins dynamically

I recently found the need to display a plugin dynamically, in a very similar way to the ‘Form Data’ plugin, in a certain PropertyData type existed within a page type. After reflecting the code for the form data plugin I was able to duplicate the functionality:

Firstly the plugin class needs to inherit from ICustomPlugInLoader, which exposes the method List()

public PlugInDescriptor[] List()
{
    if (PageAllowsComments())
    {
        // Show plugin if comments allowed
        PlugInDescriptor descriptor = PlugInDescriptor.Load(GetType());

        return new PlugInDescriptor[] { descriptor };
    }
   
    // Hide plugin if comments not allowed
    return new PlugInDescriptor[0];
}

private bool PageAllowsComments()
{
    PageData page = GetCurrentPage();

    if (page != null)
    {
        foreach (PropertyData propertyData in page.Property)
        {
            if (propertyData is CommentsXForm) return true;
        }
    }

    return false;
}

private PageData GetCurrentPage()
{
    PageData currentPage;
            
    if (PageReference.IsNullOrEmpty(base.CurrentPage.PageLink))
    {
        return null;
    }

    try
    {
        currentPage = base.CurrentPage;
    }
    catch (EPiServerException)
    {
        return null;
    }

    return currentPage;
}
Nov 20, 2008

Comments

Sep 21, 2010 10:32 AM

Thanks for this - I was looking around for a way to be able to load edit panel plug-ins on the fly depending on the base page type.
/ Ben Morris

Please login to comment.
Latest blogs
Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog

Azure AI Language – Abstractive Summarisation in Optimizely CMS

In this article, I show how the abstraction summarisation feature provided by the Azure AI Language platform, can be used within Optimizely CMS to...

Anil Patel | Apr 18, 2024 | Syndicated blog

Fix your Search & Navigation (Find) indexing job, please

Once upon a time, a colleague asked me to look into a customer database with weird spikes in database log usage. (You might start to wonder why I a...

Quan Mai | Apr 17, 2024 | Syndicated blog