Class UmbracoHelper
A helper class that provides many useful methods and functionality for using Umbraco in templates
public class UmbracoHelper
- Inheritance
-
UmbracoHelper
- Inherited Members
Remarks
This object is a request based lifetime
Constructors
UmbracoHelper(ICultureDictionaryFactory, IUmbracoComponentRenderer, IPublishedContentQuery)
Initializes a new instance of UmbracoHelper.
public UmbracoHelper(ICultureDictionaryFactory cultureDictionary, IUmbracoComponentRenderer componentRenderer, IPublishedContentQuery publishedContentQuery)
Parameters
cultureDictionary
ICultureDictionaryFactorycomponentRenderer
IUmbracoComponentRendererpublishedContentQuery
IPublishedContentQuery
Remarks
Sets the current page to the context's published content request's content item.
Properties
AssignedContentItem
Gets (or sets) the current Umbraco.Cms.Core.Models.PublishedContent.IPublishedContent item assigned to the UmbracoHelper.
public IPublishedContent AssignedContentItem { get; set; }
Property Value
- IPublishedContent
Remarks
Note that this is the assigned IPublishedContent item to the UmbracoHelper, this is not necessarily the Current IPublishedContent item being rendered that is assigned to the UmbracoContext. This IPublishedContent object is contextual to the current UmbracoHelper instance.
In some cases accessing this property will throw an exception if there is not IPublishedContent assigned to the Helper this will only ever happen if the Helper is constructed via DI during a non front-end request.
Exceptions
- InvalidOperationException
Thrown if the UmbracoHelper is constructed with an UmbracoContext and it is not a front-end request.
CultureDictionary
Returns the ICultureDictionary for access to dictionary items
public ICultureDictionary CultureDictionary { get; }
Property Value
- ICultureDictionary
Methods
Content(IEnumerable<int>)
Gets the contents corresponding to the identifiers.
public IEnumerable<IPublishedContent> Content(IEnumerable<int> ids)
Parameters
ids
IEnumerable<int>The content identifiers.
Returns
- IEnumerable<IPublishedContent>
The existing contents corresponding to the identifiers.
Remarks
If an identifier does not match an existing content, it will be missing in the returned value.
Content(IEnumerable<object>)
Gets the contents corresponding to the identifiers.
public IEnumerable<IPublishedContent> Content(IEnumerable<object> ids)
Parameters
ids
IEnumerable<object>The content identifiers.
Returns
- IEnumerable<IPublishedContent>
The existing contents corresponding to the identifiers.
Remarks
If an identifier does not match an existing content, it will be missing in the returned value.
Content(IEnumerable<string>)
Gets the contents corresponding to the identifiers.
public IEnumerable<IPublishedContent> Content(IEnumerable<string> ids)
Parameters
ids
IEnumerable<string>The content identifiers.
Returns
- IEnumerable<IPublishedContent>
The existing contents corresponding to the identifiers.
Remarks
If an identifier does not match an existing content, it will be missing in the returned value.
Content(IEnumerable<GuidUdi>)
Gets the contents corresponding to the identifiers.
public IEnumerable<IPublishedContent> Content(IEnumerable<GuidUdi> ids)
Parameters
ids
IEnumerable<GuidUdi>The content identifiers.
Returns
- IEnumerable<IPublishedContent>
The existing contents corresponding to the identifiers.
Remarks
If an identifier does not match an existing content, it will be missing in the returned value.
Content(IEnumerable<Udi>)
Gets the contents corresponding to the identifiers.
public IEnumerable<IPublishedContent> Content(IEnumerable<Udi> ids)
Parameters
ids
IEnumerable<Udi>The content identifiers.
Returns
- IEnumerable<IPublishedContent>
The existing contents corresponding to the identifiers.
Remarks
If an identifier does not match an existing content, it will be missing in the returned value.
Content(Guid)
Gets a content item from the cache.
public IPublishedContent? Content(Guid id)
Parameters
id
GuidThe key of the content item.
Returns
- IPublishedContent
The content, or null of the content item is not in the cache.
Content(params Guid[])
Gets content items from the cache.
public IEnumerable<IPublishedContent> Content(params Guid[] ids)
Parameters
ids
Guid[]The keys of the content items.
Returns
- IEnumerable<IPublishedContent>
The content items that were found in the cache.
Content(int)
Gets a content item from the cache.
public IPublishedContent? Content(int id)
Parameters
id
intThe unique identifier of the content item.
Returns
- IPublishedContent
The content, or null of the content item is not in the cache.
Content(params int[])
Gets content items from the cache.
public IEnumerable<IPublishedContent> Content(params int[] ids)
Parameters
ids
int[]The unique identifiers of the content items.
Returns
- IEnumerable<IPublishedContent>
The content items that were found in the cache.
Content(object)
Gets a content item from the cache.
public IPublishedContent? Content(object id)
Parameters
id
objectThe unique identifier, or the key, of the content item.
Returns
- IPublishedContent
The content, or null of the content item is not in the cache.
Content(params object[])
Gets content items from the cache.
public IEnumerable<IPublishedContent> Content(params object[] ids)
Parameters
ids
object[]The unique identifiers, or the keys, of the content items.
Returns
- IEnumerable<IPublishedContent>
The content items that were found in the cache.
Remarks
Does not support mixing identifiers and keys.
Content(string)
Gets a content item from the cache.
public IPublishedContent? Content(string id)
Parameters
id
stringThe unique identifier, or the key, of the content item.
Returns
- IPublishedContent
The content, or null of the content item is not in the cache.
Content(params string[])
Gets content items from the cache.
public IEnumerable<IPublishedContent> Content(params string[] ids)
Parameters
ids
string[]The unique identifiers, or the keys, of the content items.
Returns
- IEnumerable<IPublishedContent>
The content items that were found in the cache.
Remarks
Does not support mixing identifiers and keys.
Content(params GuidUdi[])
Gets the contents corresponding to the identifiers.
public IEnumerable<IPublishedContent> Content(params GuidUdi[] ids)
Parameters
ids
GuidUdi[]The content identifiers.
Returns
- IEnumerable<IPublishedContent>
The existing contents corresponding to the identifiers.
Remarks
If an identifier does not match an existing content, it will be missing in the returned value.
Content(Udi)
public IPublishedContent? Content(Udi id)
Parameters
id
Udi
Returns
- IPublishedContent
Content(params Udi[])
Gets the contents corresponding to the identifiers.
public IEnumerable<IPublishedContent> Content(params Udi[] ids)
Parameters
ids
Udi[]The content identifiers.
Returns
- IEnumerable<IPublishedContent>
The existing contents corresponding to the identifiers.
Remarks
If an identifier does not match an existing content, it will be missing in the returned value.
ContentAtRoot()
public IEnumerable<IPublishedContent> ContentAtRoot()
Returns
- IEnumerable<IPublishedContent>
GetDictionaryValue(string)
Returns the dictionary value for the key specified
public string? GetDictionaryValue(string key)
Parameters
key
string
Returns
GetDictionaryValue(string, CultureInfo)
Returns the dictionary value for the key specified, and if empty returns the specified default fall back value
public string? GetDictionaryValue(string key, CultureInfo specificCulture)
Parameters
key
stringkey of dictionary item
specificCulture
CultureInfothe specific culture on which the result well be back upon
Returns
GetDictionaryValueOrDefault(string, CultureInfo, string)
Returns the dictionary value for the key specified, and if empty returns the specified default fall back value
public string GetDictionaryValueOrDefault(string key, CultureInfo specificCulture, string defaultValue)
Parameters
key
stringkey of dictionary item
specificCulture
CultureInfothe specific culture on which the result well be back upon
defaultValue
stringfall back text if dictionary item is empty - Name altText to match Umbraco.Field
Returns
GetDictionaryValueOrDefault(string, string)
Returns the dictionary value for the key specified, and if empty returns the specified default fall back value
public string GetDictionaryValueOrDefault(string key, string defaultValue)
Parameters
key
stringkey of dictionary item
defaultValue
stringfall back text if dictionary item is empty - Name altText to match Umbraco.Field
Returns
Media(IEnumerable<int>)
Gets the medias corresponding to the identifiers.
public IEnumerable<IPublishedContent> Media(IEnumerable<int> ids)
Parameters
ids
IEnumerable<int>The media identifiers.
Returns
- IEnumerable<IPublishedContent>
The existing medias corresponding to the identifiers.
Remarks
If an identifier does not match an existing media, it will be missing in the returned value.
Media(IEnumerable<object>)
Gets the medias corresponding to the identifiers.
public IEnumerable<IPublishedContent> Media(IEnumerable<object> ids)
Parameters
ids
IEnumerable<object>The media identifiers.
Returns
- IEnumerable<IPublishedContent>
The existing medias corresponding to the identifiers.
Remarks
If an identifier does not match an existing media, it will be missing in the returned value.
Media(IEnumerable<string>)
Gets the medias corresponding to the identifiers.
public IEnumerable<IPublishedContent> Media(IEnumerable<string> ids)
Parameters
ids
IEnumerable<string>The media identifiers.
Returns
- IEnumerable<IPublishedContent>
The existing medias corresponding to the identifiers.
Remarks
If an identifier does not match an existing media, it will be missing in the returned value.
Media(IEnumerable<GuidUdi>)
Gets the medias corresponding to the identifiers.
public IEnumerable<IPublishedContent> Media(IEnumerable<GuidUdi> ids)
Parameters
ids
IEnumerable<GuidUdi>The media identifiers.
Returns
- IEnumerable<IPublishedContent>
The existing medias corresponding to the identifiers.
Remarks
If an identifier does not match an existing media, it will be missing in the returned value.
Media(IEnumerable<Udi>)
Gets the medias corresponding to the identifiers.
public IEnumerable<IPublishedContent> Media(IEnumerable<Udi> ids)
Parameters
ids
IEnumerable<Udi>The media identifiers.
Returns
- IEnumerable<IPublishedContent>
The existing medias corresponding to the identifiers.
Remarks
If an identifier does not match an existing media, it will be missing in the returned value.
Media(Guid)
public IPublishedContent? Media(Guid id)
Parameters
id
Guid
Returns
- IPublishedContent
Media(int)
public IPublishedContent? Media(int id)
Parameters
id
int
Returns
- IPublishedContent
Media(params int[])
Gets the medias corresponding to the identifiers.
public IEnumerable<IPublishedContent> Media(params int[] ids)
Parameters
ids
int[]The media identifiers.
Returns
- IEnumerable<IPublishedContent>
The existing medias corresponding to the identifiers.
Remarks
If an identifier does not match an existing media, it will be missing in the returned value.
Media(object)
Overloaded method accepting an 'object' type
public IPublishedContent? Media(object id)
Parameters
id
object
Returns
- IPublishedContent
Remarks
We accept an object type because GetPropertyValue now returns an 'object', we still want to allow people to pass this result in to this method. This method will throw an exception if the value is not of type int or string.
Media(params object[])
Gets the medias corresponding to the identifiers.
public IEnumerable<IPublishedContent> Media(params object[] ids)
Parameters
ids
object[]The media identifiers.
Returns
- IEnumerable<IPublishedContent>
The existing medias corresponding to the identifiers.
Remarks
If an identifier does not match an existing media, it will be missing in the returned value.
Media(string)
public IPublishedContent? Media(string id)
Parameters
id
string
Returns
- IPublishedContent
Media(params string[])
Gets the medias corresponding to the identifiers.
public IEnumerable<IPublishedContent> Media(params string[] ids)
Parameters
ids
string[]The media identifiers.
Returns
- IEnumerable<IPublishedContent>
The existing medias corresponding to the identifiers.
Remarks
If an identifier does not match an existing media, it will be missing in the returned value.
Media(params GuidUdi[])
Gets the medias corresponding to the identifiers.
public IEnumerable<IPublishedContent> Media(params GuidUdi[] ids)
Parameters
ids
GuidUdi[]The media identifiers.
Returns
- IEnumerable<IPublishedContent>
The existing medias corresponding to the identifiers.
Remarks
If an identifier does not match an existing media, it will be missing in the returned value.
Media(Udi)
public IPublishedContent? Media(Udi id)
Parameters
id
Udi
Returns
- IPublishedContent
Media(params Udi[])
Gets the medias corresponding to the identifiers.
public IEnumerable<IPublishedContent> Media(params Udi[] ids)
Parameters
ids
Udi[]The media identifiers.
Returns
- IEnumerable<IPublishedContent>
The existing medias corresponding to the identifiers.
Remarks
If an identifier does not match an existing media, it will be missing in the returned value.
MediaAtRoot()
public IEnumerable<IPublishedContent> MediaAtRoot()
Returns
- IEnumerable<IPublishedContent>
RenderTemplateAsync(int, int?)
Renders the template for the specified pageId and an optional altTemplateId
public Task<IHtmlEncodedString> RenderTemplateAsync(int contentId, int? altTemplateId = null)
Parameters
contentId
intThe content id
altTemplateId
int?If not specified, will use the template assigned to the node
Returns
- Task<IHtmlEncodedString>