Table of Contents

Class CustomItem

Namespace
Custom.Data
Assembly
ToSic.Sxc.dll

Base class for custom data objects, which are typed and can be used in Razor Components.

It is used by 2sxc Copilot when generating base classes for custom data objects.

[PublicApi]
public class CustomItem : ITypedItem, ITyped, IEquatable<ITypedItem>
Inheritance
CustomItem
Implements

Remarks

  • Released in v17.06
  • It's not abstract, even if the most common case is to inherit, as there are cases where you want to use it directly.

Properties

Guid

The guid of the underlying entity.

[JsonPropertyOrder(-99)]
public 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.

[JsonPropertyOrder(-100)]
public 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.

[JsonIgnore]
public 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.

[JsonIgnore]
public bool IsPublished { get; }

Property Value

bool

Remarks

New in v17, see also Publishing

Metadata

Metadata of the current item, with special features.

[JsonIgnore]
public IMetadata Metadata { get; }

Property Value

IMetadata

Remarks

Added in 16.02

Presentation

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

[JsonIgnore]
public ITypedItem Presentation { get; }

Property Value

ITypedItem

Publishing

[JsonIgnore]
public 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.

[JsonIgnore]
public 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.

[JsonIgnore]
public IContentType Type { get; }

Property Value

IContentType

_item

The item - for inheriting classes to access.

protected ITypedItem _item { get; }

Property Value

ITypedItem

Remarks

This property is protected, not public, as it should only be used internally. It uses an unusual name _item to avoid naming conflicts with properties generated in inheriting classes.

Methods

AsList<T>(IEnumerable<ITypedItem>, NoParamOrder, bool)

Convert a list of Entities or TypedItems into a strongly typed list. Typically, the type will be from your AppCode.Data.

protected IEnumerable<T> AsList<T>(IEnumerable<ITypedItem> source, NoParamOrder protector = default, bool nullIfNull = false) where T : class, ITypedItemWrapper16, ITypedItem, new()

Parameters

source IEnumerable<ITypedItem>
protector NoParamOrder
nullIfNull bool

Returns

IEnumerable<T>

Type Parameters

T

Remarks

BETA in v17.03

As<T>(ITypedItem)

Convert an Entity or TypedItem into a strongly typed object. Typically, the type will be from your AppCode.Data.

protected T As<T>(ITypedItem item) where T : class, ITypedItemWrapper16, ITypedItem, new()

Parameters

item ITypedItem

Returns

T

Type Parameters

T

Remarks

BETA in v17.03

Attribute(string, NoParamOrder, string, bool?)

Return a value as a raw HTML string for using inside an attribute. Usage like title='@item.Attribute("Title")' It will do a few things such as:

  1. Ensure dates are in the ISO format
  2. Ensure numbers are in a neutral format such as 14.27 and never 14,27
  3. Html encode any characters which would cause trouble such as quotes
public IRawHtmlString Attribute(string name, NoParamOrder noParamOrder = default, string fallback = null, bool? required = null)

Parameters

name string

Name of the property

noParamOrder NoParamOrder

see Convention: Named Parameters

fallback string

Value to use if the property specified by name doesn't exist

required bool?

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

Returns

IRawHtmlString

Bool(string, NoParamOrder, bool, bool?)

Get a property and return the value as a bool. If conversion fails, will return default false or what is specified in the fallback.

public bool Bool(string name, NoParamOrder noParamOrder = default, bool fallback = false, bool? required = null)

Parameters

name string

property name

noParamOrder NoParamOrder

see Convention: Named Parameters

fallback bool

optional fallback if conversion fails

required bool?

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

Returns

bool

Value as bool

Child(string, NoParamOrder, bool?)

A single item from a field.

public 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.

public T Child<T>(string name, 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.

public IEnumerable<ITypedItem> Children(string field, 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.

public IEnumerable<T> Children<T>(string field, 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

ContainsKey(string)

Check if this typed object has a property of this specified name. It's case-insensitive.

public bool ContainsKey(string name)

Parameters

name string

the name like Image; some objects also support path to sub-property like Author.Name

Returns

bool

Remarks

Adding in 16.03 (WIP)

DateTime(string, NoParamOrder, DateTime, bool?)

Get a property and return the value as a DateTime. If conversion fails, will return default 0001-01-01 or what is specified in the fallback.

public DateTime DateTime(string name, NoParamOrder noParamOrder = default, DateTime fallback = default, bool? required = null)

Parameters

name string

property name

noParamOrder NoParamOrder

see Convention: Named Parameters

fallback DateTime

optional fallback if conversion fails

required bool?

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

Returns

DateTime

Value as DateTime

Decimal(string, NoParamOrder, decimal, bool?)

Get a property and return the value as a decimal. If conversion fails, will return default 0 or what is specified in the fallback.

public decimal Decimal(string name, NoParamOrder noParamOrder = default, decimal fallback = 0, bool? required = null)

Parameters

name string

property name

noParamOrder NoParamOrder

see Convention: Named Parameters

fallback decimal

optional fallback if conversion fails

required bool?

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

Returns

decimal

Value as decimal

Double(string, NoParamOrder, double, bool?)

Get a property and return the value as a double. If conversion fails, will return default 0 or what is specified in the fallback.

public double Double(string name, NoParamOrder noParamOrder = default, double fallback = 0, bool? required = null)

Parameters

name string

property name

noParamOrder NoParamOrder

see Convention: Named Parameters

fallback double

optional fallback if conversion fails

required bool?

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

Returns

double

Value as double

Equals(object)

Ensure that the equality check is done correctly. If two objects wrap the same item, they will be considered equal.

public override bool Equals(object b)

Parameters

b object

Returns

bool

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.

public 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
public 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

Float(string, NoParamOrder, float, bool?)

Get a property and return the value as a float. If conversion fails, will return default 0 or what is specified in the fallback.

public float Float(string name, NoParamOrder noParamOrder = default, float fallback = 0, bool? required = null)

Parameters

name string

property name

noParamOrder NoParamOrder

see Convention: Named Parameters

fallback float

optional fallback if conversion fails

required bool?

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

Returns

float

Value as float

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.

public 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

Get(string, NoParamOrder, bool?, string)

Get a property.

public object Get(string name, NoParamOrder noParamOrder = default, bool? required = null, string language = null)

Parameters

name string

the property name like Image - or path to sub-property like Author.Name (new v15)

noParamOrder NoParamOrder

see Convention: Named Parameters

required bool?

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

language string

Optional language like de, de-ch or de,en to determine which values to check. Will ignore languages not in the data model. On items that don't have ML data it will be ignored. new v17.10

Returns

object

The result if found or null; or error if the object is in strict mode

Remarks

  • parameter languages added in 17.10

Get<TValue>(string, NoParamOrder, TValue, bool?, 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.

Since the parameter fallback determines the type TValue you can just write this like `something.Get("Title", fallback: "no title")

public TValue Get<TValue>(string name, NoParamOrder noParamOrder = default, TValue fallback = default, bool? required = null, string language = null)

Parameters

name string

the property name like Image - or path to sub-property like Author.Name (new v15)

noParamOrder NoParamOrder

see Convention: Named Parameters

fallback TValue

the fallback value to provide if not found

required bool?

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

language string

Optional language like de, de-ch or de,en to determine which values to check. Will ignore languages not in the data model. On items that don't have ML data it will be ignored. new v17.10

Returns

TValue

The typed value, or the default like null or 0 if casting isn't possible.

Type Parameters

TValue

The expected type, like string, int, etc. Note that you don't need to specify it, if you specify the fallback property.

Remarks

  • Added in v15
  • parameter languages added in 17.10

Gps(string, NoParamOrder, bool?)

Get the GPS coordinates of a GPS field as a typed object.

public 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

public 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, 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;

public 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 string

Name of a field

noParamOrder NoParamOrder

see Convention: Named Parameters

tweak 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 object

An optional multiplier, usually used to create urls which resize to a part of the default content-size. Like 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 like 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)
  • tweak added in 18.03

Int(string, NoParamOrder, int, bool?)

Get a property and return the value as a int. If conversion fails, will return default 0 or what is specified in the fallback.

public int Int(string name, NoParamOrder noParamOrder = default, int fallback = 0, bool? required = null)

Parameters

name string

property name

noParamOrder NoParamOrder

see Convention: Named Parameters

fallback int

optional fallback if conversion fails

required bool?

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

Returns

int

Value as int

IsEmpty(string, NoParamOrder, string)

Check if this typed object has a property of this specified name, and has real data. The opposite version of this is IsNotEmpty(...)

Important

This method is optimized for use in Razor-like scenarios. It's behavior is super-useful but maybe not always expected.

  • If the value is a string, and is empty or only contains whitespace (even &nbsp;) it is regarded as empty.
  • If the returned value is an empty list (e.g. a field containing relationships, without any items in it) it is regarded as empty.

If you need a different kind of check, just .Get(...) the value and perform the checks in your code.

public bool IsEmpty(string name, NoParamOrder noParamOrder = default, string language = null)

Parameters

name string

the property name like Image; some objects also support path to sub-property like Author.Name

noParamOrder NoParamOrder

see Convention: Named Parameters

language string

Optional language like de, de-ch or de,en to determine which values to check. Will ignore languages not in the data model. On items that don't have ML data it will be ignored. new v17.10

Returns

bool

true if the property exists and has a real value. If it returned an empty list, it will also return false

Remarks

  • Added in 16.03
  • language parameter added in 17.10

IsNotEmpty(string, NoParamOrder, string)

Check if this typed object has a property of this specified name, and has real data. The opposite version of this is IsEmpty(...)

Important

This method is optimized for use in Razor-like scenarios. It's behavior is super-useful but maybe not always expected.

  • If the value is a string, and is empty or only contains whitespace (even &nbsp;) it is regarded as empty.
  • If the returned value is an empty list (e.g. a field containing relationships, without any items in it) it is regarded as empty.

If you need a different kind of check, just .Get(...) the value and perform the checks in your code.

public bool IsNotEmpty(string name, NoParamOrder noParamOrder = default, string language = null)

Parameters

name string

the property name like Image; some objects also support path to sub-property like Author.Name

noParamOrder NoParamOrder

see Convention: Named Parameters

language string

Optional language like de, de-ch or de,en to determine which values to check. Will ignore languages not in the data model. On items that don't have ML data it will be ignored. new v17.10

Returns

bool

true if the property exists and has a real value. If it returned an empty list, it will also return false

Remarks

  • Added in 16.03
  • language parameter added in 17.10

Keys(NoParamOrder, IEnumerable<string>)

Get all the keys available in this Model (all the parameters passed in). This is used to sometimes run early checks if all the expected parameters have been provided.

public IEnumerable<string> Keys(NoParamOrder noParamOrder = default, IEnumerable<string> only = null)

Parameters

noParamOrder NoParamOrder

see Convention: Named Parameters

only IEnumerable<string>

Only return the keys specified here, if found. Typical use: only: new [] { "Key1", "Key2" }. Useful to check if all or any specific keys exist.

Returns

IEnumerable<string>

Remarks

Added in 16.03

Long(string, NoParamOrder, long, bool?)

Get a property and return the value as a long. If conversion fails, will return default 0 or what is specified in the fallback.

public long Long(string name, NoParamOrder noParamOrder = default, long fallback = 0, bool? required = null)

Parameters

name string

property name

noParamOrder NoParamOrder

see Convention: Named Parameters

fallback long

optional fallback if conversion fails

required bool?

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

Returns

long

Value as long

Parent(NoParamOrder, bool?, string, string)

Get either the current parent or the first parent which would be found on .Parents(...).

public 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.

public 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.

public 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.

public 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, 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;

public 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 string

Name of a field

noParamOrder NoParamOrder

see Convention: Named Parameters

tweak 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 object

An optional multiplier, usually used to create urls which resize to a part of the default content-size. Like 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 like 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 like 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
  • tweak added in 18.03

String(string, NoParamOrder, string, bool?, object)

Get a property and return the value as a string. If conversion fails, will return default null or what is specified in the fallback.

public string String(string name, NoParamOrder noParamOrder = default, string fallback = null, bool? required = null, object scrubHtml = null)

Parameters

name string

property name

noParamOrder NoParamOrder

see Convention: Named Parameters

fallback string

optional fallback if conversion fails

required bool?

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

scrubHtml object

If true, will remove all HTML tags from the string. If p will remove all p tags, if div,span will remove these tags. This is the same as using Kit.Scrub.All(...) or .Only(...). For more detailed scrubbing, use the Kit.Scrub`

Returns

string

Value as string

ToString()

Override ToString to give more information about the current object

public override string ToString()

Returns

string

Url(string, NoParamOrder, string, bool?)

Get a url from a field. It will do sanitation / url-corrections for special characters etc.

On TypedItems it will also auto-convert values such as file:72 or page:14.

public string Url(string name, NoParamOrder noParamOrder = default, string fallback = null, bool? required = null)

Parameters

name string

The field name.

noParamOrder NoParamOrder

see Convention: Named Parameters

fallback string

optional fallback if conversion fails

required bool?

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

Returns

string

A url converted if possible. If the field contains anything else such as hello then it will not be modified.

Operators

operator ==(CustomItem, CustomItem)

Ensure that the equality check is done correctly. If two objects wrap the same item, they will be considered equal.

public static bool operator ==(CustomItem item1, CustomItem item2)

Parameters

item1 CustomItem

first item to compare

item2 CustomItem

second item to compare

Returns

bool

true, if both wrappers are the same type and wrap the same entity

operator !=(CustomItem, CustomItem)

Ensure that the equality check is done correctly. If two objects wrap the same item, they will be considered equal.

public static bool operator !=(CustomItem item1, CustomItem item2)

Parameters

item1 CustomItem

first item to compare

item2 CustomItem

second item to compare

Returns

bool

false, if both wrappers are the same type and wrap the same entity