The dynamic content function in EPiServer allows developers to create functionality in code which will then be utilized by an editor working in the HTML editor.
A Dynamic Content class does not define a whole page, rather just a small section of it. This makes it suitable for smaller functionality that will be inserted inline into texts on the site by the editor. User Controls can be used to implement the user interface part of a dynamic content object. A nice analogy would be a .NET UserControl, which in fact can be used to implement the user interface of a dynamic content object.
Dynamic Content has the following advantages:
- Enables the developer to render the contents with any .NET derived type of control directly into texts written by an editor.
- Dynamic Content is fully integrated into the EPiServer CMS core and improves performance since the parsing engine is optimized for it.
- Uses hashes to make sure only EPiServer CMS code can update the contents.
- Fully adapts ASP.NET functionality.
Recommendations for usage
The Dynamic Content concept was introduced in EPiServer CMS before blocks became available. Blocks and dynamic content are somewhat overlapping concepts and we generally recommend blocks where possible. Since EPiServer CMS 7.5, it's possible to drag and drop a block into a rich text area which makes it possible to use the block as a "dynamic content" in the text.
The main limitation with blocks in rich text is that this is always treated as a block level element. Dynamic content can be treated as either an inline or block element. So if you need to insert inline content, for instance the latest company results or a phone number, dynamic content is still the preferred way to do this.
Dynamic Content has functionality to auto-generate an editor for the settings for dynamic content. This still uses the editing system that was used in EPiServer CMS 6; this system has some limitations that you should be aware of if you want to use the automatic editing functionality:
- The media system introduced in EPiServer 7.5 is not supported. This means that it’s not possible to automatically create editors to select a file, for instance, an image.
- Also, the editor that is used is an older version of Tiny MCE that might work slightly different than the main Tiny MCE editor. One example is that this is not upgraded to fully support Internet Explorer 11. Another drawback is that you cannot link to a file in the media system inside the HTML editor.
- There is no support for new content types introduced in EPiServer 7 and above, for instance, Content Areas.
These limitations are only valid when you are using the auto-generated UI. You can always create your own editorial UI for your dynamic content to overcome most of these limitations.
Developing dynamic content
When developing dynamic content, consider the following:
- Create a .NET class that implements the IDynamicContentControl (contains Web Forms specific methods) or IDynamicContentView (for both MVC and WebForms) interface.
- You need to register the dynamic content type using either the DynamicContentPlugIn attribute or by registering it in the web.config.
- The editor creates an instance of the dynamic content class, sets its properties and places it as desired in the EPiServer CMS HTML editor.
- When the page is rendered, EPiServer CMS replaces the dynamic content design time markup with the actual HTML output of the dynamic content class or its delegated control