HomeDev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunitySubmit a ticketLog In
GitHubNuGetDev CommunitySubmit a ticket

Render dynamic content with interfaces

Describes how to use interfaces to render dynamic content.



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 Create a plug-in.

IDynamicContentBase interface

The IDynamicContentBase interface is the fundamental building block of a dynamic content class, which 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 in the editorial interface. The properties within the collection should be members of the plug-in class so that you can consume the values entered from the editorial interface.

IDynamicContentView interface

IDynamicContentView extends IDynamicContentBase with methods to support rendering in Web Forms and MVC. You should use this interface when you implement custom dynamic content.

  • void Render(TextWriter writer) – The Render method writes HTML to display on the page. Visitors see this when they visit the page on which the object is rendered.

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 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.