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.
Inherited Members
Namespace: ToSic.Sxc.Data
Assembly: ToSic.Sxc.dll
Syntax
[PublicApi]
public interface ITypedItem : ITyped, ICanBeItem
Remarks
Introduced in 2sxc 16.01
Properties
| Improve this Doc View SourceDyn
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.
Declaration
dynamic Dyn { get; }
Property Value
Type | Description |
---|---|
dynamic |
Guid
The guid of the underlying entity.
Declaration
Guid Guid { get; }
Property Value
Type | Description |
---|---|
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.
Declaration
int Id { get; }
Property Value
Type | Description |
---|---|
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
.
Declaration
bool IsDemoItem { get; }
Property Value
Type | Description |
---|---|
bool | True if this is the item configured in the view-settings, false if not. |
Metadata
Metadata of the current item, with special features.
Declaration
IMetadata Metadata { get; }
Property Value
Type | Description |
---|---|
IMetadata |
Remarks
Added in 16.02
Presentation
The presentation item or null
if it doesn't exist.
Declaration
ITypedItem Presentation { get; }
Property Value
Type | Description |
---|---|
ITypedItem |
Title
The title of this item. This is always available no matter what the underlying field for the title is.
Declaration
string Title { get; }
Property Value
Type | Description |
---|---|
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.
Declaration
IContentType Type { get; }
Property Value
Type | Description |
---|---|
IContentType |
Methods
| Improve this Doc View SourceChild(string, string, bool?)
A single item from a field. If the field doesn't exist or is empty, will return null.
Declaration
ITypedItem Child(string name, string noParamOrder = "Params must be named (https://go.2sxc.org/named-params)", bool? required = null)
Parameters
Type | Name | Description |
---|---|---|
string | name | Name of the field |
string | noParamOrder | |
bool? | required | throw error if |
Returns
Type | Description |
---|---|
ITypedItem |
Children(string, string, 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", typeName) gives you the ability to restrict to a type.
Please check the tutorials on 2sxc.org/dnn-tutorials/ for more info.
Declaration
IEnumerable<ITypedItem> Children(string field = null, string noParamOrder = "Params must be named (https://go.2sxc.org/named-params)", string type = null, bool? required = null)
Parameters
Type | Name | Description |
---|---|---|
string | field | Optional field filter - would only return items that point to the current item in a specific field name. |
string | noParamOrder | |
string | type | Optional type filter - would only return items of this type. |
bool? | required | throw error if |
Returns
Type | Description |
---|---|
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()
Field(string, string, 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.
Declaration
IField Field(string name, string noParamOrder = "Params must be named (https://go.2sxc.org/named-params)", bool? required = null)
Parameters
Type | Name | Description |
---|---|---|
string | name | Name of the property |
string | noParamOrder | |
bool? | required | throw error if |
Returns
Type | Description |
---|---|
IField |
File(string, string, 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
Declaration
IFile File(string name, string noParamOrder = "Params must be named (https://go.2sxc.org/named-params)", bool? required = null)
Parameters
Type | Name | Description |
---|---|---|
string | name | property name |
string | noParamOrder | |
bool? | required | throw error if |
Returns
Type | Description |
---|---|
IFile |
Remarks
Added in 16.02
Folder(string, string, 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.
Declaration
IFolder Folder(string name, string noParamOrder = "Params must be named (https://go.2sxc.org/named-params)", bool? required = null)
Parameters
Type | Name | Description |
---|---|---|
string | name | property name |
string | noParamOrder | |
bool? | required | throw error if |
Returns
Type | Description |
---|---|
IFolder | The Folder object |
Remarks
Added in 16.02
Html(string, string, object, bool?, object, bool?, 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
Declaration
IHtmlTag Html(string name, string noParamOrder = "Params must be named (https://go.2sxc.org/named-params)", object container = null, bool? toolbar = null, object imageSettings = null, bool? required = null, bool debug = false)
Parameters
Type | Name | Description |
---|---|---|
string | name | the field name |
string | noParamOrder | |
object | container | A wrapper tag for the result.
It's either a RazorBlade tag such as |
bool? | toolbar | Override default toolbar behavior on this field. See docs |
object | imageSettings | Settings for resizing. Default is |
bool? | required | throw error if |
bool | debug | Activate debug visualization to better see alignments and such. |
Returns
Type | Description |
---|---|
IHtmlTag |
Remarks
- Added in 2sxc 16.01
- Only works on Razor files inheriting from Hybrid14 or newer
Parents(string, 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.
Declaration
IEnumerable<ITypedItem> Parents(string noParamOrder = "Params must be named (https://go.2sxc.org/named-params)", string type = null, string field = null)
Parameters
Type | Name | Description |
---|---|---|
string | noParamOrder | |
string | type | Optional type filter - would only return items of this type. |
string | field | Optional field filter - would only return items that point to the current item in a specific field name. |
Returns
Type | Description |
---|---|
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()
Picture(string, string, object, object, object, string, string, string, 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, string, 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, string, object, object, string, string, string, 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;
Declaration
IResponsivePicture Picture(string name, string noParamOrder = "Params must be named (https://go.2sxc.org/named-params)", object settings = null, object factor = null, object width = null, string imgAlt = null, string imgAltFallback = null, string imgClass = null, object toolbar = null, object recipe = null)
Parameters
Type | Name | Description |
---|---|---|
string | name | Name of a field |
string | noParamOrder | |
object | settings |
|
object | factor | An optional multiplier, usually used to create urls which resize to a part of the default content-size. Eg. 0.5. |
object | width | An optional, fixed width of the image |
string | imgAlt | Optional |
string | imgAltFallback | Optional |
string | imgClass | Optional |
object | toolbar | Provide a custom toolbar or |
object | recipe | Optional recipe = instructions how to create the various variants of this link. Can be any one of these:
TODO: DOCS not quite ready |
Returns
Type | Description |
---|---|
IResponsivePicture |
|
Remarks
- Added to ITypedItem in v16.03
- We have this
Picture
method but noImg
method, as we don't recommended that in responsive HTML5