Render dynamic content with interfaces
Describes how to use interfaces to render dynamic content.
Caution
Dynamic content is deprecated in Optimizely Content Management System (CMS 12). Use blocks instead. While existing solutions will continue to work, you should not build new solutions on this API. It will be phased out in the future.
CMS uses the following interfaces to render Dynamic Content. Use these interfaces unless you use the plug-in functionality that automatically wraps a user control described in Creating a plug-in.
IDynamicContentBase interface
The IDynamicContentBase
interface is the fundamental building block of a dynamic content class. This interface is implicitly used when you use the DynamicContentPlugInAttribute
but its use is automatic and hidden. The interface's methods and properties are explained as follows.
string State { get; set; }
Get and set the State
string for an instance. The class should use this value to serialize and deserialize its internal state. State
can be null or an empty string.
PropertyDataCollection Properties { get; }
Get a collection of Optimizely Properties that are presented in the editorial interface. The properties within the collection should be members of the plug-in class so that the values entered from the editorial interface can be consumed.
IDynamicContentView interface
IDynamicContentView
extends IDynamicContentBase
with methods to support rendering in both Web Forms and MVC. You should use this interface when you implement a custom Dynamic Content.
void Render(TextWriter writer)
The Render
method writes HTML to display on the page. This is what the visitor actually sees when they visit the page the object is being rendered on.
IDynamicContentControl interface
IDynamicContentControl
extends IDynamicContentBase
with methods to support rendering in Web Forms using controls.
System.Web.UI.Control GetControl(TemplateControl hostPage)
The GetControl
method returns a reference to a control that can be anything that derives from control including web controls, user controls, and custom controls. You can use hostPage.LoadControl
to load user controls.
System.Web.Mvc.IView interface
The IDynamicContentView
interface supports both MVC and Web Forms but in some cases you need access to the ViewContext
class. If a dynamic content class implements this interface, it takes precedence over the other interfaces when running inside an MVC view.
Updated 5 months ago