Dynamic Entity Objects
Whenever you create a content-type - like Person - and want to work with the data in your C# Razor templates, you'll be working with a Dynamic Entity.
👉 also read about AsDynamic(...)
Code example using a Dynamic Entity
We'll assume we have a Content Type called Book with the following properties:
- Title (text, 1-line)
- Teaser (text, multi-line)
- Description (text, html)
- ReleaseDate (date)
- Author (entity - another content item)
Here's a code example in a C# Razor template:
<!--
The default variable for the current item is Content,
we'll just use another name for this sample
note that .Title is automatically provided,
because the content-type has the property title.
-->
<h1>@Content.Title</h1>
<div>@Content.Description</div>
<div>Author: @Content.Author.FullName</div>
So basically all properties of this book can be shown using [Object].[PropertyName]
- for example Content.ReleaseDate
.
👉 more about this on Dynamic Entity Properties
Working with unpublished/draft items
TODO: write something about how-to-check if published/unpublished, navigating it, etc. - or link to such a page
Discover More in the Razor Tutorials
We have an rich series of Razor tutorials. You should really check them out 👍.
History
- Introduced in 2sxc 01.00
- Changed to use interface IDynamicEntity in 6.x
- Draft/Published introduced in 2sxc 7.x
- Presentation introduced in 2sxc 7.x
- Modified introduced in 2sxc 8.x
- Implemented .net equality comparer in 2sxc 9.42
- Parents added in 2sxc 9.42
- Get added in 2sxc 9.42 and added to interface IDynamicEntity in 10.07
- Parents introduced in 2sxc 9.42, and added to interface IDynamicEntity in 10.07
- IsDemoItem property added in 2sxc 10.06
- Changed dynamic access to a property to return a DynamicEntity which is enumerable in 10.27