我在webpart区域内有一个带有转发器的页面,用于显示旋转内容(在旋转木马中)。轮播的内容来自/ Carousel /文件夹,它是页面本身的子项。
我想做什么,但不知道如何根据/ Carousel /文件夹的存在来设置webpart区域的可见性:如果/ Carousel /文件夹在那里 - >显示webpart区域/转发器,如果不是 - >把它藏起来。谢谢!
答案 0 :(得分:2)
答案 1 :(得分:1)
我已多次遇到同样的事情,所以我实际上专门针对这类内容构建了一个宏(因为正如你所评论的那样,可见性在webpart区域而不是转发器上)
这是宏方法
[MacroMethod(typeof(bool), "Finds if at least 1 child exists under the given node for navigation purposes",1 )]
[MacroMethodParam(0, "int", typeof(int), "The Node ID")]
[MacroMethodParam(1, "Text", typeof(string), "A list of valid page types, comma, semi-colon, or bar seperated")]
[MacroMethodParam(2, "bool", typeof(bool), "Include Unpuglished pages (false by default)")]
[MacroMethodParam(3, "bool", typeof(bool), "Include Documents Hidden from Navigation (false by default)")]
public static object NodeHasNavigationChildren(EvaluationContext context, params object[] parameters)
{
switch (parameters.Length)
{
case 1:
return HBS_Gen_Module.GeneralHelpers.NodeHasNavigationChildren(ValidationHelper.GetInteger(parameters[0], -1));
case 2:
return HBS_Gen_Module.GeneralHelpers.NodeHasNavigationChildren(ValidationHelper.GetInteger(parameters[0], -1), ValidationHelper.GetString(parameters[1], ""));
case 3:
return HBS_Gen_Module.GeneralHelpers.NodeHasNavigationChildren(ValidationHelper.GetInteger(parameters[0], -1), ValidationHelper.GetString(parameters[1], ""), ValidationHelper.GetBoolean(parameters[2], false));
case 4:
return HBS_Gen_Module.GeneralHelpers.NodeHasNavigationChildren(ValidationHelper.GetInteger(parameters[0], -1), ValidationHelper.GetString(parameters[1], ""), ValidationHelper.GetBoolean(parameters[2], false), ValidationHelper.GetBoolean(parameters[3], false));
default:
case 0:
throw new NotSupportedException();
}
}
以下是它所调用的实际方法:
/// <summary>
/// Checks if there exists a Node that should be displayed in navigation, this is more advanced than the "NodeHasChildren" which only checks for published children, and doesn't have page type and DocumentHiddenInNavigation checks
/// </summary>
/// <param name="NodeID">The Node ID</param>
/// <param name="PageTypes">Semi-colon, bar, or comma seperated list of class names</param>
/// <param name="IncludeUnpublished">If unpublished should be included (default false)</param>
/// <param name="IncludeHiddenNavigationDocuments">If Documents hidden from navigation should be included (default false)</param>
/// <returns>If there exists at least 1 child that fits</returns>
public static bool NodeHasNavigationChildren(int NodeID, string PageTypes = "", bool IncludeUnpublished = false, bool IncludeHiddenNavigationDocuments = false)
{
return CacheHelper.Cache(cs => NodeHasNavigationChildrenCache(cs, NodeID, PageTypes, IncludeUnpublished, IncludeHiddenNavigationDocuments), new CacheSettings(1440, new string[] { "NodeHasNavigationChildren", NodeID.ToString(), PageTypes, IncludeUnpublished.ToString(), IncludeHiddenNavigationDocuments.ToString() }));
}
private static bool NodeHasNavigationChildrenCache(CacheSettings cs, int NodeID, string PageTypes = "", bool IncludeUnpublished = true, bool IncludeHiddenNavigationDocuments = false)
{
var ChildQuery = DocumentHelper.GetDocuments().WhereEquals("NodeParentID", NodeID).Columns("NodeID").TopN(1);
if (IncludeUnpublished)
{
ChildQuery.Published(false);
}
if (IncludeHiddenNavigationDocuments)
{
ChildQuery.Where("DocumentMenuItemHideInNavigation = 0 or DocumentMenuItemHideInNavigation = 1");
}
else
{
ChildQuery.WhereEquals("DocumentMenuItemHideInNavigation", false);
}
if (!string.IsNullOrWhiteSpace(PageTypes))
{
ChildQuery.WhereIn("ClassName", PageTypes.Split(";|,".ToCharArray(), StringSplitOptions.RemoveEmptyEntries));
}
if(cs.Cached)
{
TreeNode ParentNode = DocumentHelper.GetDocuments().WhereEquals("NodeID", NodeID).Published(false).FirstObject;
if(ParentNode != null) {
cs.CacheDependency = CacheHelper.GetCacheDependency("node|"+SiteContext.CurrentSiteName+"|" + ParentNode.NodeAliasPath + "|childnodes");
}
}
return ChildQuery.Count > 0;
}
答案 2 :(得分:1)
您不必实施任何自定义宏方法。在这种情况下,您可以简单地利用Kentico的默认方法,例如存在:
{% CurrentDocument.Children.Exists("DocumentName==\"Carousel\"") %}