Class PublishedElementExtensions
Provides extension methods for IPublishedElement
.
Inheritance
Namespace: Umbraco.Web
Assembly: Umbraco.Web.dll
Syntax
public static class PublishedElementExtensions
Methods
View SourceHasProperty(IPublishedElement, String)
Gets a value indicating whether the content has a property identified by its alias.
Declaration
public static bool HasProperty(this IPublishedElement content, string alias)
Parameters
Type | Name | Description |
---|---|---|
IPublishedElement | content | The content. |
System.String | alias | The property alias. |
Returns
Type | Description |
---|---|
System.Boolean | A value indicating whether the content has the property identified by the alias. |
Remarks
The content may have a property, and that property may not have a value.
HasValue(IPublishedElement, String, String, String)
Gets a value indicating whether the content has a value for a property identified by its alias.
Declaration
public static bool HasValue(this IPublishedElement content, string alias, string culture = null, string segment = null)
Parameters
Type | Name | Description |
---|---|---|
IPublishedElement | content | |
System.String | alias | |
System.String | culture | |
System.String | segment |
Returns
Type | Description |
---|---|
System.Boolean |
Remarks
Returns true if GetProperty(alias)
is not null
and GetProperty(alias).HasValue
is true
.
IsComposedOf(IPublishedElement, String)
Gets a value indicating whether the content is of a content type composed of the given alias
Declaration
public static bool IsComposedOf(this IPublishedElement content, string alias)
Parameters
Type | Name | Description |
---|---|---|
IPublishedElement | content | The content. |
System.String | alias | The content type alias. |
Returns
Type | Description |
---|---|
System.Boolean | A value indicating whether the content is of a content type composed of a content type identified by the alias. |
IsVisible(IPublishedElement)
Gets a value indicating whether the content is visible.
Declaration
public static bool IsVisible(this IPublishedElement content)
Parameters
Type | Name | Description |
---|---|---|
IPublishedElement | content | The content. |
Returns
Type | Description |
---|---|
System.Boolean | A value indicating whether the content is visible. |
Remarks
A content is not visible if it has an umbracoNaviHide property with a value of "1". Otherwise, the content is visible.
MediaUrl(IPublishedContent, String, UrlMode, String)
Gets the URL for a media.
Declaration
public static string MediaUrl(this IPublishedContent content, string culture = null, UrlMode mode = UrlMode.Default, string propertyAlias = "umbracoFile")
Parameters
Type | Name | Description |
---|---|---|
IPublishedContent | content | The content item. |
System.String | culture | The culture (use current culture by default). |
UrlMode | mode | The URL mode (use site configuration by default). |
System.String | propertyAlias | The alias of the property (use 'umbracoFile' by default). |
Returns
Type | Description |
---|---|
System.String | The URL for the media. |
Remarks
The value of this property is contextual. It depends on the 'current' request uri, if any. In addition, when the content type is multi-lingual, this is the URL for the specified culture. Otherwise, it is the invariant URL.
OfTypes<T>(IEnumerable<T>, String[])
Declaration
public static IEnumerable<T> OfTypes<T>(this IEnumerable<T> contents, params string[] types)
where T : IPublishedElement
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<T> | contents | |
System.String[] | types |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T> |
Type Parameters
Name | Description |
---|---|
T |
ToIndexedArray<TContent>(IEnumerable<TContent>)
Declaration
public static IndexedArrayItem<TContent>[] ToIndexedArray<TContent>(this IEnumerable<TContent> source)
where TContent : class, IPublishedElement
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<TContent> | source |
Returns
Type | Description |
---|---|
IndexedArrayItem<TContent>[] |
Type Parameters
Name | Description |
---|---|
TContent |
Value(IPublishedElement, String, String, String, Fallback, Object)
Gets the value of a content's property identified by its alias.
Declaration
public static object Value(this IPublishedElement content, string alias, string culture = null, string segment = null, Fallback fallback = default(Fallback), object defaultValue = null)
Parameters
Type | Name | Description |
---|---|---|
IPublishedElement | content | The content. |
System.String | alias | The property alias. |
System.String | culture | The variation language. |
System.String | segment | The variation segment. |
Fallback | fallback | Optional fallback strategy. |
System.Object | defaultValue | The default value. |
Returns
Type | Description |
---|---|
System.Object | The value of the content's property identified by the alias, if it exists, otherwise a default value. |
Remarks
The value comes from IPublishedProperty
field Value
ie it is suitable for use when rendering content.
If no property with the specified alias exists, or if the property has no value, returns defaultValue
.
If eg a numeric property wants to default to 0 when value source is empty, this has to be done in the converter.
The alias is case-insensitive.
Value<T>(IPublishedElement, String, String, String, Fallback, T)
Gets the value of a content's property identified by its alias, converted to a specified type.
Declaration
public static T Value<T>(this IPublishedElement content, string alias, string culture = null, string segment = null, Fallback fallback = default(Fallback), T defaultValue = null)
Parameters
Type | Name | Description |
---|---|---|
IPublishedElement | content | The content. |
System.String | alias | The property alias. |
System.String | culture | The variation language. |
System.String | segment | The variation segment. |
Fallback | fallback | Optional fallback strategy. |
T | defaultValue | The default value. |
Returns
Type | Description |
---|---|
T | The value of the content's property identified by the alias, converted to the specified type. |
Type Parameters
Name | Description |
---|---|
T | The target property type. |
Remarks
The value comes from IPublishedProperty
field Value
ie it is suitable for use when rendering content.
If no property with the specified alias exists, or if the property has no value, or if it could not be converted, returns default(T)
.
If eg a numeric property wants to default to 0 when value source is empty, this has to be done in the converter.
The alias is case-insensitive.