Search Results for

    Show / Hide Table of Contents
    View Source

    Class UmbracoHelper

    A helper class that provides many useful methods and functionality for using Umbraco in templates

    Inheritance
    object
    Namespace: Umbraco.Cms.Web.Common
    Assembly: Umbraco.Web.Common.dll
    Syntax
    public class UmbracoHelper
    Remarks

    This object is a request based lifetime

    Constructors

    View Source

    UmbracoHelper(ICultureDictionaryFactory, IUmbracoComponentRenderer, IPublishedContentQuery)

    Initializes a new instance of UmbracoHelper.

    Declaration
    public UmbracoHelper(ICultureDictionaryFactory cultureDictionary, IUmbracoComponentRenderer componentRenderer, IPublishedContentQuery publishedContentQuery)
    Parameters
    Type Name Description
    ICultureDictionaryFactory cultureDictionary
    IUmbracoComponentRenderer componentRenderer
    IPublishedContentQuery publishedContentQuery
    Remarks

    Sets the current page to the context's published content request's content item.

    Properties

    View Source

    AssignedContentItem

    Gets (or sets) the current IPublishedContent item assigned to the UmbracoHelper.

    Declaration
    public IPublishedContent AssignedContentItem { get; set; }
    Property Value
    Type Description
    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
    Type Condition
    InvalidOperationException

    Thrown if the UmbracoHelper is constructed with an UmbracoContext and it is not a front-end request.

    View Source

    CultureDictionary

    Gets the ICultureDictionary for the current UI Culture for access to dictionary items

    Declaration
    public ICultureDictionary CultureDictionary { get; }
    Property Value
    Type Description
    ICultureDictionary

    Methods

    View Source

    Content(IEnumerable<int>)

    Gets the contents corresponding to the identifiers.

    Declaration
    public IEnumerable<IPublishedContent> Content(IEnumerable<int> ids)
    Parameters
    Type Name Description
    IEnumerable<int> ids

    The content identifiers.

    Returns
    Type Description
    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.

    View Source

    Content(IEnumerable<object>)

    Gets the contents corresponding to the identifiers.

    Declaration
    public IEnumerable<IPublishedContent> Content(IEnumerable<object> ids)
    Parameters
    Type Name Description
    IEnumerable<object> ids

    The content identifiers.

    Returns
    Type Description
    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.

    View Source

    Content(IEnumerable<string>)

    Gets the contents corresponding to the identifiers.

    Declaration
    public IEnumerable<IPublishedContent> Content(IEnumerable<string> ids)
    Parameters
    Type Name Description
    IEnumerable<string> ids

    The content identifiers.

    Returns
    Type Description
    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.

    View Source

    Content(IEnumerable<GuidUdi>)

    Gets the contents corresponding to the identifiers.

    Declaration
    public IEnumerable<IPublishedContent> Content(IEnumerable<GuidUdi> ids)
    Parameters
    Type Name Description
    IEnumerable<GuidUdi> ids

    The content identifiers.

    Returns
    Type Description
    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.

    View Source

    Content(IEnumerable<Udi>)

    Gets the contents corresponding to the identifiers.

    Declaration
    public IEnumerable<IPublishedContent> Content(IEnumerable<Udi> ids)
    Parameters
    Type Name Description
    IEnumerable<Udi> ids

    The content identifiers.

    Returns
    Type Description
    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.

    View Source

    Content(Guid)

    Gets a content item from the cache.

    Declaration
    public IPublishedContent? Content(Guid id)
    Parameters
    Type Name Description
    Guid id

    The key of the content item.

    Returns
    Type Description
    IPublishedContent

    The content, or null of the content item is not in the cache.

    View Source

    Content(params Guid[])

    Gets content items from the cache.

    Declaration
    public IEnumerable<IPublishedContent> Content(params Guid[] ids)
    Parameters
    Type Name Description
    Guid[] ids

    The keys of the content items.

    Returns
    Type Description
    IEnumerable<IPublishedContent>

    The content items that were found in the cache.

    View Source

    Content(int)

    Gets a content item from the cache.

    Declaration
    public IPublishedContent? Content(int id)
    Parameters
    Type Name Description
    int id

    The unique identifier of the content item.

    Returns
    Type Description
    IPublishedContent

    The content, or null of the content item is not in the cache.

    View Source

    Content(params int[])

    Gets content items from the cache.

    Declaration
    public IEnumerable<IPublishedContent> Content(params int[] ids)
    Parameters
    Type Name Description
    int[] ids

    The unique identifiers of the content items.

    Returns
    Type Description
    IEnumerable<IPublishedContent>

    The content items that were found in the cache.

    View Source

    Content(object)

    Gets a content item from the cache.

    Declaration
    public IPublishedContent? Content(object id)
    Parameters
    Type Name Description
    object id

    The unique identifier, or the key, of the content item.

    Returns
    Type Description
    IPublishedContent

    The content, or null of the content item is not in the cache.

    View Source

    Content(params object[])

    Gets content items from the cache.

    Declaration
    public IEnumerable<IPublishedContent> Content(params object[] ids)
    Parameters
    Type Name Description
    object[] ids

    The unique identifiers, or the keys, of the content items.

    Returns
    Type Description
    IEnumerable<IPublishedContent>

    The content items that were found in the cache.

    Remarks

    Does not support mixing identifiers and keys.

    View Source

    Content(string)

    Gets a content item from the cache.

    Declaration
    public IPublishedContent? Content(string id)
    Parameters
    Type Name Description
    string id

    The unique identifier, or the key, of the content item.

    Returns
    Type Description
    IPublishedContent

    The content, or null of the content item is not in the cache.

    View Source

    Content(params string[])

    Gets content items from the cache.

    Declaration
    public IEnumerable<IPublishedContent> Content(params string[] ids)
    Parameters
    Type Name Description
    string[] ids

    The unique identifiers, or the keys, of the content items.

    Returns
    Type Description
    IEnumerable<IPublishedContent>

    The content items that were found in the cache.

    Remarks

    Does not support mixing identifiers and keys.

    View Source

    Content(params GuidUdi[])

    Gets the contents corresponding to the identifiers.

    Declaration
    public IEnumerable<IPublishedContent> Content(params GuidUdi[] ids)
    Parameters
    Type Name Description
    GuidUdi[] ids

    The content identifiers.

    Returns
    Type Description
    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.

    View Source

    Content(Udi)

    Declaration
    public IPublishedContent? Content(Udi id)
    Parameters
    Type Name Description
    Udi id
    Returns
    Type Description
    IPublishedContent
    View Source

    Content(params Udi[])

    Gets the contents corresponding to the identifiers.

    Declaration
    public IEnumerable<IPublishedContent> Content(params Udi[] ids)
    Parameters
    Type Name Description
    Udi[] ids

    The content identifiers.

    Returns
    Type Description
    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.

    View Source

    ContentAtRoot()

    Gets the documents at root.

    Declaration
    public IEnumerable<IPublishedContent> ContentAtRoot()
    Returns
    Type Description
    IEnumerable<IPublishedContent>

    A collection of IPublishedContent found at the root.

    View Source

    GetCultureDictionary(CultureInfo)

    Gets the ICultureDictionary for access to dictionary items for a specific culture

    Declaration
    public ICultureDictionary GetCultureDictionary(CultureInfo specificCulture)
    Parameters
    Type Name Description
    CultureInfo specificCulture

    The culture of the culture dictionary you want to retrieve.

    Returns
    Type Description
    ICultureDictionary

    Returns the culture dictionary for the specified culture.

    View Source

    GetDictionaryValue(string)

    Returns the dictionary value for the key specified

    Declaration
    public string? GetDictionaryValue(string key)
    Parameters
    Type Name Description
    string key

    Key of dictionary item.

    Returns
    Type Description
    string

    The dictionary value, should one exist.

    View Source

    GetDictionaryValue(string, CultureInfo)

    Returns the dictionary value for the key specified, and if empty returns the specified default fall back value

    Declaration
    public string? GetDictionaryValue(string key, CultureInfo specificCulture)
    Parameters
    Type Name Description
    string key

    Key of dictionary item.

    CultureInfo specificCulture

    the specific culture on which the result well be back upon

    Returns
    Type Description
    string

    The dictionary value, should one exist.

    View Source

    GetDictionaryValueOrDefault(string, CultureInfo, string)

    Returns the dictionary value for the key specified, and if empty returns the specified default fall back value

    Declaration
    public string GetDictionaryValueOrDefault(string key, CultureInfo specificCulture, string defaultValue)
    Parameters
    Type Name Description
    string key

    Key of dictionary item.

    CultureInfo specificCulture

    The specific culture on which the result well be back upon.

    string defaultValue

    Fall back text if dictionary item is empty - Name altText to match Umbraco.Field.

    Returns
    Type Description
    string

    Returns the dictionary value, or a default value if none exists.

    View Source

    GetDictionaryValueOrDefault(string, string)

    Returns the dictionary value for the key specified, and if empty returns the specified default fall back value

    Declaration
    public string GetDictionaryValueOrDefault(string key, string defaultValue)
    Parameters
    Type Name Description
    string key

    key of dictionary item.

    string defaultValue

    fall back text if dictionary item is empty - Name altText to match Umbraco.Field.

    Returns
    Type Description
    string

    Returns the dictionary value, or a default value if none exists.

    View Source

    Media(IEnumerable<int>)

    Gets the medias corresponding to the identifiers.

    Declaration
    public IEnumerable<IPublishedContent> Media(IEnumerable<int> ids)
    Parameters
    Type Name Description
    IEnumerable<int> ids

    The media identifiers.

    Returns
    Type Description
    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.

    View Source

    Media(IEnumerable<object>)

    Gets the medias corresponding to the identifiers.

    Declaration
    public IEnumerable<IPublishedContent> Media(IEnumerable<object> ids)
    Parameters
    Type Name Description
    IEnumerable<object> ids

    The media identifiers.

    Returns
    Type Description
    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.

    View Source

    Media(IEnumerable<string>)

    Gets the medias corresponding to the identifiers.

    Declaration
    public IEnumerable<IPublishedContent> Media(IEnumerable<string> ids)
    Parameters
    Type Name Description
    IEnumerable<string> ids

    The media identifiers.

    Returns
    Type Description
    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.

    View Source

    Media(IEnumerable<GuidUdi>)

    Gets the medias corresponding to the identifiers.

    Declaration
    public IEnumerable<IPublishedContent> Media(IEnumerable<GuidUdi> ids)
    Parameters
    Type Name Description
    IEnumerable<GuidUdi> ids

    The media identifiers.

    Returns
    Type Description
    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.

    View Source

    Media(IEnumerable<Udi>)

    Gets the medias corresponding to the identifiers.

    Declaration
    public IEnumerable<IPublishedContent> Media(IEnumerable<Udi> ids)
    Parameters
    Type Name Description
    IEnumerable<Udi> ids

    The media identifiers.

    Returns
    Type Description
    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.

    View Source

    Media(Guid)

    Declaration
    public IPublishedContent? Media(Guid id)
    Parameters
    Type Name Description
    Guid id
    Returns
    Type Description
    IPublishedContent
    View Source

    Media(int)

    Declaration
    public IPublishedContent? Media(int id)
    Parameters
    Type Name Description
    int id
    Returns
    Type Description
    IPublishedContent
    View Source

    Media(params int[])

    Gets the medias corresponding to the identifiers.

    Declaration
    public IEnumerable<IPublishedContent> Media(params int[] ids)
    Parameters
    Type Name Description
    int[] ids

    The media identifiers.

    Returns
    Type Description
    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.

    View Source

    Media(object)

    Overloaded method accepting an 'object' type

    Declaration
    public IPublishedContent? Media(object id)
    Parameters
    Type Name Description
    object id
    Returns
    Type Description
    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.

    View Source

    Media(params object[])

    Gets the medias corresponding to the identifiers.

    Declaration
    public IEnumerable<IPublishedContent> Media(params object[] ids)
    Parameters
    Type Name Description
    object[] ids

    The media identifiers.

    Returns
    Type Description
    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.

    View Source

    Media(string)

    Declaration
    public IPublishedContent? Media(string id)
    Parameters
    Type Name Description
    string id
    Returns
    Type Description
    IPublishedContent
    View Source

    Media(params string[])

    Gets the medias corresponding to the identifiers.

    Declaration
    public IEnumerable<IPublishedContent> Media(params string[] ids)
    Parameters
    Type Name Description
    string[] ids

    The media identifiers.

    Returns
    Type Description
    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.

    View Source

    Media(params GuidUdi[])

    Gets the medias corresponding to the identifiers.

    Declaration
    public IEnumerable<IPublishedContent> Media(params GuidUdi[] ids)
    Parameters
    Type Name Description
    GuidUdi[] ids

    The media identifiers.

    Returns
    Type Description
    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.

    View Source

    Media(Udi)

    Declaration
    public IPublishedContent? Media(Udi id)
    Parameters
    Type Name Description
    Udi id
    Returns
    Type Description
    IPublishedContent
    View Source

    Media(params Udi[])

    Gets the medias corresponding to the identifiers.

    Declaration
    public IEnumerable<IPublishedContent> Media(params Udi[] ids)
    Parameters
    Type Name Description
    Udi[] ids

    The media identifiers.

    Returns
    Type Description
    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.

    View Source

    MediaAtRoot()

    Declaration
    public IEnumerable<IPublishedContent> MediaAtRoot()
    Returns
    Type Description
    IEnumerable<IPublishedContent>
    View Source

    RenderTemplateAsync(int, int?)

    Renders the template for the specified pageId and an optional altTemplateId

    Declaration
    public Task<IHtmlEncodedString> RenderTemplateAsync(int contentId, int? altTemplateId = null)
    Parameters
    Type Name Description
    int contentId

    The content id

    int? altTemplateId

    If not specified, will use the template assigned to the node

    Returns
    Type Description
    Task<IHtmlEncodedString>
    • Edit this page
    • View Source
    In this article
    Back to top Copyright © 2016-present Umbraco
    Generated by DocFX