Class PublishedElementExtensions
Provides extension methods for IPublishedElement
.
Inheritance
Namespace: Umbraco.Extensions
Assembly: Umbraco.Core.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, IPublishedValueFallback)
Gets a value indicating whether the content is visible.
Declaration
public static bool IsVisible(this IPublishedElement content, IPublishedValueFallback publishedValueFallback)
Parameters
Type | Name | Description |
---|---|---|
IPublishedElement | content | The content. |
IPublishedValueFallback | publishedValueFallback | The published value fallback implementation. |
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, IPublishedUrlProvider, String, UrlMode, String)
Gets the url for a media.
Declaration
public static string MediaUrl(this IPublishedContent content, IPublishedUrlProvider publishedUrlProvider, string culture = null, UrlMode mode = UrlMode.Default, string propertyAlias = "umbracoFile")
Parameters
Type | Name | Description |
---|---|---|
IPublishedContent | content | The content item. |
IPublishedUrlProvider | publishedUrlProvider | The published url provider. |
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 |
---|---|---|
IEnumerable<T> | contents | |
System.String[] | types |
Returns
Type | Description |
---|---|
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 |
---|---|---|
IEnumerable<TContent> | source |
Returns
Type | Description |
---|---|
IndexedArrayItem<TContent>[] |
Type Parameters
Name | Description |
---|---|
TContent |
Value(IPublishedElement, IPublishedValueFallback, 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, IPublishedValueFallback publishedValueFallback, string alias, string culture = null, string segment = null, Fallback fallback = default(Fallback), object defaultValue = null)
Parameters
Type | Name | Description |
---|---|---|
IPublishedElement | content | The content. |
IPublishedValueFallback | publishedValueFallback | The published value fallback implementation. |
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, IPublishedValueFallback, 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, IPublishedValueFallback publishedValueFallback, string alias, string culture = null, string segment = null, Fallback fallback = default(Fallback), T defaultValue = null)
Parameters
Type | Name | Description |
---|---|---|
IPublishedElement | content | The content. |
IPublishedValueFallback | publishedValueFallback | The published value fallback implementation. |
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.