csharp Umbraco IPublishedContent的一些有用的扩展方法。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp Umbraco IPublishedContent的一些有用的扩展方法。相关的知识,希望对你有一定的参考价值。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Web;

/// <summary>
/// A few useful extension methods for Umbraco IpublishedContent
/// </summary>
public static class UmbracoExtensions
{
    /// <summary>
    /// Aliases of doctypes that should be excluded from navigation etc.
    /// </summary>
    private readonly static string[] ExcludedAliases = new string[] 
    {
        "ExampleAlias", "AnotherExampleAlias"
    };

    /// <summary>
    /// Gets the home page relative to the current content
    /// </summary>
    /// <param name="content">The current content</param>
    /// <returns>The root node of the site</returns>
    public static IPublishedContent HomePage(this IPublishedContent content)
    {
        return content.AncestorOrSelf(1);
    }

    /// <summary>
    /// Gets whether this content has a template associated with it
    /// </summary>
    /// <param name="content">The content to check</param>
    /// <returns>Returns true if it has a template otherwise false</returns>
    public static bool HasTemplate(this IPublishedContent content)
    {
        return content.TemplateId > 0;
    }

    /// <summary>
    /// Gets whether this document should be excluded based on it's DocumentTypeAlias
    /// </summary>
    /// <param name="content">The content to check</param>
    /// <returns>True if it should be excluded otherwise false</returns>
    public static bool IsExcluded(this IPublishedContent content)
    {
        return ExcludedAliases.Contains(content.DocumentTypeAlias);
    }

    /// <summary>
    /// Gets whether this document should appear in the menu
    /// </summary>
    /// <param name="content">The content to check</param>
    /// <returns>True if it should otherwise false</returns>
    public static bool IsInMenu(this IPublishedContent content)
    {
        return content.HasTemplate() && content.IsVisible() && !content.IsExcluded();
    }
}

以上是关于csharp Umbraco IPublishedContent的一些有用的扩展方法。的主要内容,如果未能解决你的问题,请参考以下文章

csharp Umbraco获得所有重复的媒体

csharp 一堆Umbraco Membership API片段

csharp 使用Umbraco Examine API搜索多个术语。

csharp Umbraco IPublishedContent的一些有用的扩展方法。

csharp 像Umbraco的API一样的JQuery

csharp Umbraco属性的一组有用的扩展方法。