Interface ITypedItem
A typed item to access IEntity data in a strongly typed way.
[PublicApi]
[JsonConverter(typeof(DynamicJsonConverter))]
public interface ITypedItem : ITyped, IEquatable<ITypedItem>
- Inherited Members
Remarks
Previously Razor code always used dynamic IDynamicEntity objects.
This had some disadvantages when working with LINQ or advanced toolbars.
History: Introduced in 2sxc 16.01
Properties
Dyn
A dynamic accessor for properties, to quickly get values when you don't care about type safety. This is often (but not always) a IDynamicEntity.
Example: Dyn.FirstName might just work - and return the first name or null if not found.
[InternalApi_DoNotUse_MayChangeWithoutNotice("This should be avoided")]
[JsonIgnore]
dynamic Dyn { get; }
Property Value
- dynamic
Guid
The guid of the underlying entity.
Guid Guid { get; }
Property Value
Remarks
If the entity doesn't exist, it will return an empty guid
Id
The ID of the underlying entity. Use it for edit-functionality or just to have a unique number for this item.
int Id { get; }
Property Value
Remarks
If the entity doesn't exist, it will return 0
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.
IsPublished
True if this item version is published. This means that the item can exist as published, or published-with-draft, showing the published version.
Note that by default, end-users only see the published version and don't see any draft version.
bool IsPublished { get; }
Property Value
Remarks
New in v17, see also Publishing
Metadata
Metadata of the current item, with special features.
[JsonIgnore]
IMetadata Metadata { get; }
Property Value
Remarks
Added in 16.02
Presentation
The presentation item or null if it doesn't exist.
[JsonIgnore]
ITypedItem Presentation { get; }
Property Value
Publishing
IPublishing Publishing { get; }
Property Value
Title
The title of this item. This is always available no matter what the underlying field for the title is.
string Title { 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.
Type
The Content-Type of the current entity.
IContentType Type { get; }
Property Value
Methods
Child(string, NoParamOrder, bool?)
A single item from a field.
ITypedItem Child(string name, NoParamOrder noParamOrder = default, bool? required = null)
Parameters
namestringName of the field
noParamOrderNoParamOrderrequiredbool?throw error if
namedoesn't exist, see Convention: Property Required Name Checks
Returns
- ITypedItem
The ITypedItem. If the field doesn't exist or is empty, will return null.
Child<T>(string, NoParamOrder, bool?)
Get a child and return with specified custom type.
T Child<T>(string name = null, NoParamOrder protector = default, bool? required = null) where T : class, ICanWrapData, new()
Parameters
namestringName of the field
protectorNoParamOrderrequiredbool?throw error if
namedoesn't exist, see Convention: Property Required Name Checks
Returns
- T
Type Parameters
T
Remarks
New v17.05
Children(string, NoParamOrder, string, bool?)
A typed 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", type: typeName) gives you the ability to restrict to a type.
Please check the tutorials on 2sxc.org/dnn-tutorials/ for more info.
IEnumerable<ITypedItem> Children(string field = null, NoParamOrder noParamOrder = default, string type = null, bool? required = null)
Parameters
fieldstringOptional field filter - would only return items that point to the current item in a specific field name.
noParamOrderNoParamOrdertypestringOptional type filter - would only return items of this type.
requiredbool?throw error if
namedoesn't exist, see Convention: Property Required Name Checks
Returns
- IEnumerable<ITypedItem>
A list of all items pointing here (filtered), converted to DynamicEntity for convenience.
Remarks
Note that the parameter-order is reversed to the Parents()
Children<T>(string, NoParamOrder, string, bool?)
A strongly typed 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", type: typeName) gives you the ability to restrict to a type.
Please check the tutorials on 2sxc.org/dnn-tutorials/ for more info.
IEnumerable<T> Children<T>(string field = null, NoParamOrder protector = default, string type = null, bool? required = null) where T : class, ICanWrapData, new()
Parameters
fieldstringName of the field
protectorNoParamOrdertypestringOptional type filter - would only return items of this type.
requiredbool?throw error if
namedoesn't exist, see Convention: Property Required Name Checks
Returns
- IEnumerable<T>
Type Parameters
T
Remarks
New v17.05
Field(string, NoParamOrder, bool?)
Get a special info-object describing a specific field in this item. This is a rich object used by other operations which need a lot of context about the item and the field.
IField Field(string name, NoParamOrder noParamOrder = default, bool? required = null)
Parameters
namestringName of the property
noParamOrderNoParamOrderrequiredbool?throw error if
namedoesn't exist, see Convention: Property Required Name Checks
Returns
File(string, NoParamOrder, bool?)
Get the file of the current field. There are a few scenarios:
- If it's a file/hyperlink field pointing to a file such as
file:27it will retrieve the file itself. - If it's a file/hyperlink field pointing to a url such as
http://xyzit will returnnull. - If it's a library field, it will just take the first file, as there is no value referencing a specific field
- If it's any other field, will return
null
IFile File(string name, NoParamOrder noParamOrder = default, bool? required = null)
Parameters
namestringproperty name
noParamOrderNoParamOrderrequiredbool?throw error if
namedoesn't exist, see Convention: Property Required Name Checks
Returns
Remarks
Added in 16.02
Folder(string, NoParamOrder, bool?)
Get the ADAM (Automatic Digital Asset Manager) for this field. This is a folder which contains all the files and possibly folders which are uploaded on exactly this field.
IFolder Folder(string name, NoParamOrder noParamOrder = default, bool? required = null)
Parameters
namestringproperty name
noParamOrderNoParamOrderrequiredbool?throw error if
namedoesn't exist, see Convention: Property Required Name Checks
Returns
- IFolder
The Folder object
Remarks
Added in 16.02
Gps(string, NoParamOrder, bool?)
Get the GPS coordinates of a GPS field as a typed object.
GpsCoordinates Gps(string name, NoParamOrder protector = default, bool? required = null)
Parameters
namestringName of a field
protectorNoParamOrderrequiredbool?throw error if
namedoesn't exist, see Convention: Property Required Name Checks
Returns
Remarks
New in v17.03
Html(string, NoParamOrder, object, bool?, object, bool?, bool, Func<ITweakInput<string>, ITweakInput<string>>)
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? required = null, bool debug = false, Func<ITweakInput<string>, ITweakInput<string>> tweak = null)
Parameters
namestringthe field name
noParamOrderNoParamOrdercontainerobjectA wrapper tag for the result. It's either a RazorBlade tag such as
Kit.HtmlTag.Div(), a string such asspanor an empty string `` to indicate no container. If not set it will default to to a div-tag. See docstoolbarbool?Override default toolbar behavior on this field. See docs
imageSettingsobjectSettings for resizing. Default is
Wysiwygbut it can also beContentor a settings object.requiredbool?throw error if
namedoesn't exist, see Convention: Property Required Name ChecksdebugboolActivate debug visualization to better see alignments and such.
tweakFunc<ITweakInput<string>, ITweakInput<string>>tweak behavior - ATM modify the input before it's processed new in v17
Returns
Remarks
- Added in 2sxc 16.01
- Added
tweakin v17 - Only works on Razor files inheriting from Hybrid14 or newer
Img(string, NoParamOrder, Func<ITweakMedia, ITweakMedia>, object, object, object, string, string, string, object, object, object)
Get a Responsive Picture object which you can then either just show, or use to construct a more customized output as you need it.
The resulting object can just be added to the html, like @pic or you can work with sub-properties as specified in the IResponsivePicture.
Important: This call only allows you to set the most common parameters factor and width.
For other parameters like height, aspectRatio, quality etc. create typed Settings Settings(object, NoParamOrder, Func<ITweakResize, ITweakResize>, object, object, object, object, string, string, string, object, string, object) and pass them in.
Note
This is the similar as using the Picture(object, object, NoParamOrder, Func<ITweakMedia, ITweakMedia>, object, object, string, string, string, object, string, object, object, object) just a bit simpler.
An important difference is that it returns null if the field does not exist or is empty, allowing you to just show nothing or use ...Picture(...) ?? someFallback;
IResponsiveImage Img(string name, NoParamOrder noParamOrder = default, Func<ITweakMedia, ITweakMedia> tweak = null, object settings = null, object factor = null, object width = null, string imgAlt = null, string imgAltFallback = null, string imgClass = null, object imgAttributes = null, object toolbar = null, object recipe = null)
Parameters
namestringName of a field
noParamOrderNoParamOrdertweakFunc<ITweakMedia, ITweakMedia>Tweak API to configure everything (new v18.03). This is recommended above using parameter names and all newer parameters will only be available on this.
settingsobject- The name of a settings configuration, like "Content", "Screen", "Square", etc.
- A standardized Image-Settings object like Settings.Child("Images.Content") - see https://go.2sxc.org/settings
- A dynamic object containing settings properties (this can also be a merged custom + standard settings)
- A strictly typed IResizeSettings object containing all settings created using ResizeSettings
factorobjectAn optional multiplier, usually used to create urls which resize to a part of the default content-size. Like 0.5.
widthobjectAn optional, fixed width of the image
imgAltstringOptional
altattribute on the createdimgtag for SEO etc. If supplied, it takes precedence to the alt-description in the image metadata which the editor added themselves. If you want to provide a fallback value (in case the metadata has no alt), useimgAltFallbackimgAltFallbackstringOptional
altattribute which is only used if theimgAltor the alt-text in the metadata are empty.imgClassstringOptional
classattribute on the createdimgtagimgAttributesobjectOptional additional attributes - as anonymous object like
new { style = "padding: 10px" }or Dictionary (new 16.07)toolbarobjectProvide a custom toolbar or
falseto not show a toolbarrecipeobjectOptional recipe = instructions how to create the various variants of this link. Can be any one of these:
- string containing variants
- Rule object
TODO: DOCS not quite ready
Returns
- IResponsiveImage
- A IResponsivePicture object which can be rendered directly. See Responsive Images API in .net
- If the field does not exist, it will return
null - If the field exists, but is empty, it will return
null
Remarks
- Added to ITypedItem in v17.04 (previously only Picture was available)
tweakadded in 18.03
Parent(NoParamOrder, bool?, string, string)
Get either the current parent or the first parent which would be found on .Parents(...).
ITypedItem Parent(NoParamOrder noParamOrder = default, bool? current = null, string type = null, string field = null)
Parameters
noParamOrderNoParamOrdercurrentbool?if set to
true, will get the Item which created the current item (the parent) which called.Child(...)or.Children(...)typestringOptional type filter - would only return items of this type.
fieldstringOptional field filter - would only return items that point to the current item in a specific field name.
Returns
- ITypedItem
either the current parent or the first parent returned by the same
.Parents(...)call.
Parent<T>(NoParamOrder, bool?, string, string)
Get either the current parent or the first parent which would be found on .Parents(...) as strongly typed.
T Parent<T>(NoParamOrder protector = default, bool? current = null, string type = null, string field = null) where T : class, ICanWrapData, new()
Parameters
protectorNoParamOrdercurrentbool?if set to
true, will get the Item which created the current item (the parent) which called.Child(...)or.Children(...)typestringOptional type filter - would only return items of this type.
fieldstringOptional field filter - would only return items that point to the current item in a specific field name.
Returns
- T
either the current parent or the first parent returned by the same
.Parents(...)call.
Type Parameters
T
Remarks
New v17.06
Parents(NoParamOrder, string, string)
A typed 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.
IEnumerable<ITypedItem> Parents(NoParamOrder noParamOrder = default, string type = null, string field = null)
Parameters
noParamOrderNoParamOrdertypestringOptional type filter - would only return items of this type.
fieldstringOptional field filter - would only return items that point to the current item in a specific field name.
Returns
- IEnumerable<ITypedItem>
A list of all items pointing here (filtered), converted to DynamicEntity for convenience.
Remarks
Note that the parameter-order is reversed to the Children()
Parents<T>(NoParamOrder, string, string)
A typed 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.
IEnumerable<T> Parents<T>(NoParamOrder protector = default, string type = null, string field = null) where T : class, ICanWrapData, new()
Parameters
protectorNoParamOrdertypestringOptional type filter - would only return items of this type. If not specified (null) will use the name of T.
fieldstringOptional field filter - would only return items that point to the current item in a specific field name.
Returns
- IEnumerable<T>
A list of all items pointing here (filtered), converted to DynamicEntity for convenience.
Type Parameters
T
Remarks
Note that the parameter-order is reversed to the Children()
Picture(string, NoParamOrder, Func<ITweakMedia, ITweakMedia>, object, object, object, string, string, string, object, string, object, object, object)
Get a Responsive Picture object which you can then either just show, or use to construct a more customized output as you need it.
The resulting object can just be added to the html, like @pic or you can work with sub-properties as specified in the IResponsivePicture.
Important: This call only allows you to set the most common parameters factor and width.
For other parameters like height, aspectRatio, quality etc. create typed Settings Settings(object, NoParamOrder, Func<ITweakResize, ITweakResize>, object, object, object, object, string, string, string, object, string, object) and pass them in.
Note
This is the similar as using the Picture(object, object, NoParamOrder, Func<ITweakMedia, ITweakMedia>, object, object, string, string, string, object, string, object, object, object) just a bit simpler.
An important difference is that it returns null if the field does not exist or is empty, allowing you to just show nothing or use ...Picture(...) ?? someFallback;
IResponsivePicture Picture(string name, NoParamOrder noParamOrder = default, Func<ITweakMedia, ITweakMedia> tweak = null, object settings = null, object factor = null, object width = null, string imgAlt = null, string imgAltFallback = null, string imgClass = null, object imgAttributes = null, string pictureClass = null, object pictureAttributes = null, object toolbar = null, object recipe = null)
Parameters
namestringName of a field
noParamOrderNoParamOrdertweakFunc<ITweakMedia, ITweakMedia>Tweak API to configure everything (new v18.03). This is recommended above using parameter names and all newer parameters will only be available on this.
settingsobject- The name of a settings configuration, like "Content", "Screen", "Square", etc.
- A standardized Image-Settings object like Settings.Child("Images.Content") - see https://go.2sxc.org/settings
- A dynamic object containing settings properties (this can also be a merged custom + standard settings)
- A strictly typed IResizeSettings object containing all settings created using ResizeSettings
factorobjectAn optional multiplier, usually used to create urls which resize to a part of the default content-size. Like 0.5.
widthobjectAn optional, fixed width of the image
imgAltstringOptional
altattribute on the createdimgtag for SEO etc. If supplied, it takes precedence to the alt-description in the image metadata which the editor added themselves. If you want to provide a fallback value (in case the metadata has no alt), useimgAltFallbackimgAltFallbackstringOptional
altattribute which is only used if theimgAltor the alt-text in the metadata are empty.imgClassstringOptional
classattribute on the createdimgtagimgAttributesobjectOptional additional attributes - as anonymous object like
new { style = "padding: 10px" }or Dictionary (new 16.07)pictureClassstringOptional
classattribute on the createdpicturetagpictureAttributesobjectOptional additional attributes - as anonymous object like
new { style = "padding: 10px" }or Dictionary (new 16.07)toolbarobjectProvide a custom toolbar or
falseto not show a toolbarrecipeobjectOptional recipe = instructions how to create the various variants of this link. Can be any one of these:
- string containing variants
- Rule object
TODO: DOCS not quite ready
Returns
- IResponsivePicture
- A IResponsivePicture object which can be rendered directly. See Responsive Images API in .net
- If the field does not exist, it will return
null - If the field exists, but is empty, it will return
null
Remarks
- Added to ITypedItem in v16.03
imgAttributes,picClassandpicAttributesadded in 16.07tweakadded in 18.03