bpedwards
Nov 20, 2008
  5027
(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
Add your own tools to the Optimizely CMS 12 admin menu

The menus in Optimizely CMS can be extended using a MenuProvider, and using the path parameter you decide what menu you want to add additional menu...

Tomas Hensrud Gulla | Oct 3, 2024 | Syndicated blog

Integrating Optimizely DAM with Your Website

This article is the second in a series about integrating Optimizely DAM with websites. It discusses how to install the necessary package and code t...

Andrew Markham | Sep 28, 2024 | Syndicated blog

Opticon 2024 - highlights

I went to Opticon in Stockholm and here are my brief highlights based on the demos, presentations and roadmaps  Optimizely CMS SaaS will start to...

Daniel Ovaska | Sep 27, 2024

Required fields support in Optimizely Graph

It's been possible to have "required" properties (value must be entered) in the CMS for a long time. The required metadata haven't been reflected i...

Jonas Bergqvist | Sep 25, 2024