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
cultureDictionaryICultureDictionaryFactorycomponentRendererIUmbracoComponentRendererpublishedContentQueryIPublishedContentQuery
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
idsIEnumerable<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
idsIEnumerable<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
idsIEnumerable<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
idsIEnumerable<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
idsIEnumerable<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
idGuidThe 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
idsGuid[]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
idintThe 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
idsint[]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
idobjectThe 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
idsobject[]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
idstringThe 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
idsstring[]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
idsGuidUdi[]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
idUdi
Returns
- IPublishedContent
Content(params Udi[])
Gets the contents corresponding to the identifiers.
public IEnumerable<IPublishedContent> Content(params Udi[] ids)
Parameters
idsUdi[]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
keystring
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
keystringkey of dictionary item
specificCultureCultureInfothe 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
keystringkey of dictionary item
specificCultureCultureInfothe specific culture on which the result well be back upon
defaultValuestringfall 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
keystringkey of dictionary item
defaultValuestringfall 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
idsIEnumerable<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
idsIEnumerable<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
idsIEnumerable<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
idsIEnumerable<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
idsIEnumerable<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
idGuid
Returns
- IPublishedContent
Media(int)
public IPublishedContent? Media(int id)
Parameters
idint
Returns
- IPublishedContent
Media(params int[])
Gets the medias corresponding to the identifiers.
public IEnumerable<IPublishedContent> Media(params int[] ids)
Parameters
idsint[]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
idobject
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
idsobject[]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
idstring
Returns
- IPublishedContent
Media(params string[])
Gets the medias corresponding to the identifiers.
public IEnumerable<IPublishedContent> Media(params string[] ids)
Parameters
idsstring[]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
idsGuidUdi[]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
idUdi
Returns
- IPublishedContent
Media(params Udi[])
Gets the medias corresponding to the identifiers.
public IEnumerable<IPublishedContent> Media(params Udi[] ids)
Parameters
idsUdi[]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
contentIdintThe content id
altTemplateIdint?If not specified, will use the template assigned to the node
Returns
- Task<IHtmlEncodedString>