November Happy Hour will be moved to Thursday December 5th.

bpedwards
Nov 20, 2008
  5045
(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 SaaS CMS + Coveo Search Page

Short on time but need a listing feature with filters, pagination, and sorting? Create a fully functional Coveo-powered search page driven by data...

Damian Smutek | Nov 21, 2024 | Syndicated blog

Optimizely SaaS CMS DAM Picker (Interim)

Simplify your Optimizely SaaS CMS workflow with the Interim DAM Picker Chrome extension. Seamlessly integrate your DAM system, streamlining asset...

Andy Blyth | Nov 21, 2024 | Syndicated blog

Optimizely CMS Roadmap

Explore Optimizely CMS's latest roadmap, packed with developer-focused updates. From SaaS speed to Visual Builder enhancements, developer tooling...

Andy Blyth | Nov 21, 2024 | Syndicated blog

Set Default Culture in Optimizely CMS 12

Take control over culture-specific operations like date and time formatting.

Tomas Hensrud Gulla | Nov 15, 2024 | Syndicated blog