bpedwards
Nov 20, 2008
  4998
(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
Opti ID overview

Opti ID allows you to log in once and switch between Optimizely products using Okta, Entra ID, or a local account. You can also manage all your use...

K Khan | Jul 26, 2024

Getting Started with Optimizely SaaS using Next.js Starter App - Extend a component - Part 3

This is the final part of our Optimizely SaaS CMS proof-of-concept (POC) blog series. In this post, we'll dive into extending a component within th...

Raghavendra Murthy | Jul 23, 2024 | Syndicated blog

Optimizely Graph – Faceting with Geta Categories

Overview As Optimizely Graph (and Content Cloud SaaS) makes its global debut, it is known that there are going to be some bugs and quirks. One of t...

Eric Markson | Jul 22, 2024 | Syndicated blog

Integration Bynder (DAM) with Optimizely

Bynder is a comprehensive digital asset management (DAM) platform that enables businesses to efficiently manage, store, organize, and share their...

Sanjay Kumar | Jul 22, 2024