Try our conversational search powered by Generative AI!

Loading...
Area: Optimizely CMS
ARCHIVED This content is retired and no longer maintained. See the latest version here.

Recommended reading 

Introduction

When you create a component definition it is possible to automatically plug in this to a view. This is done by defining plug-in paths to one or several containers you want to plug in to. A plug-in path is a unique string that describes the plug-in area. EPiServer provides helper classes with string constants in order to plug-in to an area without having to type the plug-in area as a string. For instance you could add the following to your component:

C#
private readonly string[] _plugInPaths = new string[] { EPiServer.Web.PlugInAreas.DefaultAssetsGroup };

public override string[] PlugInPaths
{
    get { return _plugInPaths; }
}

Plugging in component hierarchies

You can plug in entire component hierarchies by adding children to the top level component that you create in the CreateComponent method. The following example shows how to plug in a new tab to the dashboard with two components:

C#
public override IComponent CreateComponent()
{
    var root = new ComponentContainer() { PlugInPath = "/samples/dashboard/mycustomtab" };
    root.Settings["numberOfColumns"] = 2;
    root.Settings["title"] = "My custom tab";

    var fileManager = new FileManagementComponent().CreateComponent();
    fileManager.Settings["column"] = 0;
    root.Add(fileManager);

    var pageTree = new PageTreeComponent().CreateComponent();
    pageTree.Settings["column"] = 1;
    root.Add(pageTree);

    return root;
}
In this example it is possible for other plug-ins to plug into the new tab due to the definition of PlugInPath = "/samples/dashboard/mycustomtab".

When doing this you should use a special component definition class that creates a root component that does not have a reference to the component definition of the hierarchy. This is because the CreateComponent method is called both when creating new views but also when loading a personalized hierarchy.
Do you find this information helpful? Please log in to provide feedback.

Last updated: Feb 23, 2015

Recommended reading