Interface IDynamicEntity
This is a wrapper for IEntity objects. It provides nicer access to underlying properties and automatically handles things like multi-language etc. The underlying IEntity IEntity is in the Entity property.
Normally you will use it without caring about these internals.
Please check @HowTo.DynamicCode.DynamicEntity
[PublicApi]
public interface IDynamicEntity : IHasDecorators<IEntity>, ICanDebug
- Inherited Members
Properties
AnyProperty
A Dynamic Entity always contains an item of your data - a book, person, blog-post or a piece of content.
Since the object is dynamic, you can just use .IsFemale
or whatever other property your item has.
It is treated as a dynamic
so you can just output it, or cast it to the expected type.
dynamic AnyProperty { get; }
Property Value
- dynamic
EntityGuid
The guid of the underlying entity.
Guid EntityGuid { get; }
Property Value
Remarks
If the entity doesn't exist, it will return an empty guid
EntityId
The ID of the underlying entity. Use it for edit-functionality or just to have a unique number for this item.
int EntityId { get; }
Property Value
Remarks
If the entity doesn't exist, it will return 0
EntityTitle
The title of this item. This is always available no matter what the underlying field for the title is.
string EntityTitle { get; }
Property Value
- string
The title of the underlying entity. In rare cases where no title-field is known, it can be null. It can also be null if there is no underlying entity.
Remarks
This returns a string which is usually what's expected. In previous versions (before v15) 2sxc it returned an object.
EntityType
The type name of the current entity. This provides the nice name like "Person" and not the technical internal StaticName
string EntityType { get; }
Property Value
IsDemoItem
Many templates show demo data.
If the template code must know if it's the demo item or
real data, use .IsDemoItem
.
bool IsDemoItem { get; }
Property Value
- bool
True if this is the item configured in the view-settings, false if not.
Remarks
New in 10.07 on IDynamicEntity, new in 16.02 on ITypedEntity
IsPublished
Tells us if this data item is published or still draft. Default is true.
bool IsPublished { get; }
Property Value
Metadata
The type name of the current entity. This provides the nice name like "Person" and not the technical internal StaticName
IMetadata Metadata { get; }
Property Value
Remarks
- Added in v13
- Changed type name to
IMetadata
fromIDynamicMetadata
in 16.02; same type, different type name
Presentation
Contains presentation settings for an item - if they exist.
This is a functionality of the CMS, where an instance of an item can be configured to show in a specific way.
Normally it's used when something like an address has various show-settings (like how the map should visualize this address).
The presentation-info is therefor not-null IF
- the content belongs to this module instance
- the view-configuration of this module is configured to have presentation items
- there is either a default presentation configured in the view, or the user has manually edited the presentation settings
dynamic Presentation { get; }
Property Value
- dynamic
An IDynamicEntity with the presentation item (or the demo-presentation), otherwise null.
Methods
Children(string, string)
A dynamic list of sub-items. Important for LINQ style querying or just
working with various lists. Note that for getting child items of this item you
can just use the properties, like content.Authors.
But using Children("Authors", typeName) gives you the ability to restrict to a type.
Please check the tutorials on 2sxc.org/dnn-tutorials/ for more info.
List<IDynamicEntity> Children(string field = null, string type = null)
Parameters
field
stringOptional field filter - would only return items that point to the current item in a specific field name.
type
stringOptional type filter - would only return items of this type.
Returns
- List<IDynamicEntity>
A list of all items pointing here (filtered), converted to DynamicEntity for convenience.
Remarks
New in 10.21.00 - note also that the parameter-order is reversed to the Parents()
Field(string)
Get a Field-object of a property of this entity, to use with services like the IImageService which also need more information like the metadata.
IField Field(string name)
Parameters
name
string
Returns
Remarks
History: Added in v13.10
Get(string)
Get a value of the entity. Usually you will prefer the quick access like @content.FirstName - which will give you the same things as content.Get("FirstName"). There are two cases to use this:
- when you dynamically assemble the field name in your code, like when using App.Resources or similar use cases.
- to access a field which has a conflicting name with this object, like Get("Parents")
dynamic Get(string name)
Parameters
name
string
Returns
- dynamic
An object which can be either a string, number, boolean or List<IDynamicEntity>, depending on the field type. Will return null if the field was not found.
Get(string, NoParamOrder, string, bool, bool?)
dynamic Get(string name, NoParamOrder noParamOrder = default, string language = null, bool convertLinks = true, bool? debug = null)
Parameters
name
stringnoParamOrder
NoParamOrderlanguage
stringconvertLinks
booldebug
bool?
Returns
- dynamic
GetDraft()
Get the draft item of this item if this is a content-item which is published, and has a draft.
dynamic GetDraft()
Returns
- dynamic
Returns a dynamic entity if there is a draft, or null if there is no draft.
GetPublished()
Get the published item of this item if this is a content-item which is draft, and has a published.
dynamic GetPublished()
Returns
- dynamic
Returns a dynamic entity if there is a draft, or null if there is no draft.
Get<TValue>(string)
Get a value using the name - and cast it to the expected strong type. For example to get an int even though it's stored as decimal.
TValue Get<TValue>(string name)
Parameters
name
stringthe property name like
Image
- or path likeAuthor.Name
(new v15)
Returns
- TValue
The typed value, or the
default
likenull
or0
if casting isn't possible.
Type Parameters
TValue
The expected type, like
string
,int
, etc.
Remarks
Added in v15
Get<TValue>(string, NoParamOrder, TValue)
TValue Get<TValue>(string name, NoParamOrder noParamOrder = default, TValue fallback = default)
Parameters
name
stringnoParamOrder
NoParamOrderfallback
TValue
Returns
- TValue
Type Parameters
TValue
Html(string, NoParamOrder, object, bool?, object, bool)
Show a field in the expected / best possible way. As of now it's meant for WYSIWYG fields with Very-Rich Text. See DynamicEntity / TypedItem .Html(...) Method new v16.01
IHtmlTag Html(string name, NoParamOrder noParamOrder = default, object container = null, bool? toolbar = null, object imageSettings = null, bool debug = false)
Parameters
name
stringthe field name
noParamOrder
NoParamOrdercontainer
objectA wrapper tag for the result. It's either a RazorBlade tag such as
Kit.HtmlTag.Div()
, a string such asspan
or an empty string `` to indicate no container. If not set it will default to to a div-tag. See docstoolbar
bool?Override default toolbar behavior on this field. See docs
imageSettings
objectSettings for resizing. Default is
Wysiwyg
but it can also beContent
or a settings object.debug
boolActivate debug visualization to better see alignments and such.
Returns
Remarks
- Added in 2sxc 16.01
- Only works on Razor files inheriting from Hybrid14 or newer
Parents(string, string)
A dynamic list of entities which point to this item. Important for LINQ style querying or just
working with various lists. Note that for getting child items of this item you
can just use the properties, like content.Authors.
Please check the tutorials on 2sxc.org/dnn-tutorials/ for more info.
List<IDynamicEntity> Parents(string type = null, string field = null)
Parameters
type
stringOptional type filter - would only return items of this type.
field
stringOptional field filter - would only return items that point to the current item in a specific field name.
Returns
- List<IDynamicEntity>
A list of all items pointing here (filtered), converted to DynamicEntity for convenience.
Remarks
New in 9.42 - note also that the parameter-order is reversed to the Children()