Interface ITypedItem
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.
[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
name
stringName of the field
noParamOrder
NoParamOrderrequired
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
stringName of the field
protector
NoParamOrderrequired
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
stringOptional field filter - would only return items that point to the current item in a specific field name.
noParamOrder
NoParamOrdertype
stringOptional 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
stringName of the field
protector
NoParamOrdertype
stringOptional 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
stringName of the property
noParamOrder
NoParamOrderrequired
bool?throw error if
name
doesn'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:27
it will retrieve the file itself. - If it's a file/hyperlink field pointing to a url such as
http://xyz
it 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
name
stringproperty name
noParamOrder
NoParamOrderrequired
bool?throw error if
name
doesn'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
name
stringproperty name
noParamOrder
NoParamOrderrequired
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
stringName of a field
protector
NoParamOrderrequired
bool?throw error if
name
doesn'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
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.required
bool?throw error if
name
doesn't exist, see Convention: Property Required Name Checksdebug
boolActivate 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
Remarks
- Added in 2sxc 16.01
- Added
tweak
in 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
name
stringName of a field
noParamOrder
NoParamOrdertweak
Func<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.
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
objectAn optional multiplier, usually used to create urls which resize to a part of the default content-size. Like 0.5.
width
objectAn optional, fixed width of the image
imgAlt
stringOptional
alt
attribute on the createdimg
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), useimgAltFallback
imgAltFallback
stringOptional
alt
attribute which is only used if theimgAlt
or the alt-text in the metadata are empty.imgClass
stringOptional
class
attribute on the createdimg
tagimgAttributes
objectOptional additional attributes - as anonymous object like
new { style = "padding: 10px" }
or Dictionary (new 16.07)toolbar
objectProvide a custom toolbar or
false
to not show a toolbarrecipe
objectOptional 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)
tweak
added 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
noParamOrder
NoParamOrdercurrent
bool?if set to
true
, will get the Item which created the current item (the parent) which called.Child(...)
or.Children(...)
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
- 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
NoParamOrdercurrent
bool?if set to
true
, will get the Item which created the current item (the parent) which called.Child(...)
or.Children(...)
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
- 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
NoParamOrdertype
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
- 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
NoParamOrdertype
stringOptional type filter - would only return items of this type. If not specified (null) will use the name of T.
field
stringOptional 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
name
stringName of a field
noParamOrder
NoParamOrdertweak
Func<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.
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
objectAn optional multiplier, usually used to create urls which resize to a part of the default content-size. Like 0.5.
width
objectAn optional, fixed width of the image
imgAlt
stringOptional
alt
attribute on the createdimg
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), useimgAltFallback
imgAltFallback
stringOptional
alt
attribute which is only used if theimgAlt
or the alt-text in the metadata are empty.imgClass
stringOptional
class
attribute on the createdimg
tagimgAttributes
objectOptional additional attributes - as anonymous object like
new { style = "padding: 10px" }
or Dictionary (new 16.07)pictureClass
stringOptional
class
attribute on the createdpicture
tagpictureAttributes
objectOptional additional attributes - as anonymous object like
new { style = "padding: 10px" }
or Dictionary (new 16.07)toolbar
objectProvide a custom toolbar or
false
to not show a toolbarrecipe
objectOptional 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
,picClass
andpicAttributes
added in 16.07tweak
added in 18.03