Try our conversational search powered by Generative AI!

bpedwards
Nov 20, 2008
  4969
(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
Azure AI Language – Extractive Summarisation in Optimizely CMS

In this article, I demonstrate how extractive summarisation, provided by the Azure AI Language platform, can be leveraged to produce a set of summa...

Anil Patel | Apr 26, 2024 | Syndicated blog

Optimizely Unit Testing Using CmsContentScaffolding Package

Introduction Unit tests shouldn't be created just for business logic, but also for the content and rules defined for content creation (available...

MilosR | Apr 26, 2024

Solving the mystery of high memory usage

Sometimes, my work is easy, the problem could be resolved with one look (when I’m lucky enough to look at where it needs to be looked, just like th...

Quan Mai | Apr 22, 2024 | Syndicated blog

Search & Navigation reporting improvements

From version 16.1.0 there are some updates on the statistics pages: Add pagination to search phrase list Allows choosing a custom date range to get...

Phong | Apr 22, 2024