Table of Contents

Interface ITypedItem

Namespace
ToSic.Sxc.Data
Assembly
ToSic.Sxc.dll

A typed object to access data. Previously Razor code always used dynamic IDynamicEntity objects. This had some disadvantages when working with LINQ or advanced toolbars.

[PublicApi]
[JsonConverter(typeof(DynamicJsonConverter))]
public interface ITypedItem : ITyped, IEquatable<ITypedItem>
Inherited Members

Remarks

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.

dynamic Dyn { get; }

Property Value

dynamic

Guid

The guid of the underlying entity.

Guid Guid { get; }

Property Value

Guid

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

int

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

bool

Remarks

New in v17, see also Publishing

Metadata

Metadata of the current item, with special features.

IMetadata Metadata { get; }

Property Value

IMetadata

Remarks

Added in 16.02

Presentation

The presentation item or null if it doesn't exist.

ITypedItem Presentation { get; }

Property Value

ITypedItem

Publishing

IPublishing Publishing { get; }

Property Value

IPublishing

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

IContentType

Methods

Child(string, NoParamOrder, bool?)

A single item from a field.

ITypedItem Child(string name, NoParamOrder noParamOrder = default, bool? required = null)

Parameters

name string

Name of the field

noParamOrder NoParamOrder

see Convention: Named Parameters

required bool?

throw error if name doesn'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, ITypedItemWrapper16, ITypedItem, new()

Parameters

name string

Name of the field

protector NoParamOrder

see Convention: Named Parameters

required bool?

throw error if name doesn'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

field string

Optional field filter - would only return items that point to the current item in a specific field name.

noParamOrder NoParamOrder

see Convention: Named Parameters

type string

Optional type filter - would only return items of this type.

required bool?

throw error if name doesn'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, ITypedItemWrapper16, ITypedItem, new()

Parameters

field string

Name of the field

protector NoParamOrder

see Convention: Named Parameters

type string

Optional type filter - would only return items of this type.

required bool?

throw error if name doesn'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

name string

Name of the property

noParamOrder NoParamOrder

see Convention: Named Parameters

required bool?

throw error if name doesn't exist, see Convention: Property Required Name Checks

Returns

IField

File(string, NoParamOrder, bool?)

Get the file of the current field. There are a few scenarios:

  1. If it's a file/hyperlink field pointing to a file such as file:27 it will retrieve the file itself.
  2. If it's a file/hyperlink field pointing to a url such as http://xyz it will return null.
  3. If it's a library field, it will just take the first file, as there is no value referencing a specific field
  4. If it's any other field, will return null
IFile File(string name, NoParamOrder noParamOrder = default, bool? required = null)

Parameters

name string

property name

noParamOrder NoParamOrder

see Convention: Named Parameters

required bool?

throw error if name doesn't exist, see Convention: Property Required Name Checks

Returns

IFile

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

name string

property name

noParamOrder NoParamOrder

see Convention: Named Parameters

required bool?

throw error if name doesn'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

name string

Name of a field

protector NoParamOrder

see Convention: Named Parameters

required bool?

throw error if name doesn't exist, see Convention: Property Required Name Checks

Returns

GpsCoordinates

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

name string

the field name

noParamOrder NoParamOrder

see Convention: Named Parameters

container object

A wrapper tag for the result. It's either a RazorBlade tag such as Kit.HtmlTag.Div(), a string such as span or an empty string `` to indicate no container. If not set it will default to to a div-tag. See docs

toolbar bool?

Override default toolbar behavior on this field. See docs

imageSettings object

Settings for resizing. Default is Wysiwyg but it can also be Content or a settings object.

required bool?

throw error if name doesn't exist, see Convention: Property Required Name Checks

debug bool

Activate debug visualization to better see alignments and such.

tweak Func<ITweakInput<string>, ITweakInput<string>>

tweak behavior - ATM modify the input before it's processed new in v17

Returns

IHtmlTag

Remarks

  • Added in 2sxc 16.01
  • Added tweak in v17
  • Only works on Razor files inheriting from Hybrid14 or newer

Img(string, NoParamOrder, 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, 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, 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, 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

name string

Name of a field

noParamOrder NoParamOrder

see Convention: Named Parameters

settings object
  • 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
factor object

An optional multiplier, usually used to create urls which resize to a part of the default content-size. Eg. 0.5.

width object

An optional, fixed width of the image

imgAlt string

Optional alt attribute on the created img tag 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), use imgAltFallback

imgAltFallback string

Optional alt attribute which is only used if the imgAlt or the alt-text in the metadata are empty.

imgClass string

Optional class attribute on the created img tag

imgAttributes object

Optional additional attributes - as anonymous object eg new { style = "padding: 10px" } or Dictionary (new 16.07)

toolbar object

Provide a custom toolbar or false to not show a toolbar

recipe object

Optional 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

Remarks

  • Added to ITypedItem in v17.04 (previously only Picture was available)

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

noParamOrder NoParamOrder

see Convention: Named Parameters

current bool?

if set to true, will get the Item which created the current item (the parent) which called .Child(...) or .Children(...)

type string

Optional type filter - would only return items of this type.

field string

Optional 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, ITypedItemWrapper16, ITypedItem, new()

Parameters

protector NoParamOrder

see Convention: Named Parameters

current bool?

if set to true, will get the Item which created the current item (the parent) which called .Child(...) or .Children(...)

type string

Optional type filter - would only return items of this type.

field string

Optional 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

noParamOrder NoParamOrder

see Convention: Named Parameters

type string

Optional type filter - would only return items of this type.

field string

Optional 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, ITypedItemWrapper16, ITypedItem, new()

Parameters

protector NoParamOrder

see Convention: Named Parameters

type string

Optional type filter - would only return items of this type. If not specified (null) will use the name of T.

field string

Optional 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, 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, 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, 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, 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

name string

Name of a field

noParamOrder NoParamOrder

see Convention: Named Parameters

settings object
  • 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
factor object

An optional multiplier, usually used to create urls which resize to a part of the default content-size. Eg. 0.5.

width object

An optional, fixed width of the image

imgAlt string

Optional alt attribute on the created img tag 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), use imgAltFallback

imgAltFallback string

Optional alt attribute which is only used if the imgAlt or the alt-text in the metadata are empty.

imgClass string

Optional class attribute on the created img tag

imgAttributes object

Optional additional attributes - as anonymous object eg new { style = "padding: 10px" } or Dictionary (new 16.07)

pictureClass string

Optional class attribute on the created picture tag

pictureAttributes object

Optional additional attributes - as anonymous object eg new { style = "padding: 10px" } or Dictionary (new 16.07)

toolbar object

Provide a custom toolbar or false to not show a toolbar

recipe object

Optional 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

Remarks

  • Added to ITypedItem in v16.03
  • imgAttributes, picClass and picAttributes added in 16.07