Kentico - 分层查看器 - 不同菜单类的不同转换
Kentico - Hierarchical Viewer - Different Transformations for Different MenuClass
我使用 Hierarchical Viewer 来构建菜单。我想实现但不知道如何在页眉和页脚转换中执行 If 语句来说明:如果菜单 Class 包含 "menu-large",则显示 abc,否则显示 xyz ,如下所示。我的转型是 Text/XML。感谢您的帮助!
{%
result = "<ul class=\"dropdown-menu\">"; // default value
if(HTMLEncode(DocumentMenuClass).Contains("menu-large")) {result ="<ul class=\"dropdown-menu megamenu\"><div class=\"container megamenu-container\"><div class=\"row\">"}
return result;
#%}
我首先要检查的是 HTMLEncode(DocumentMenuClass)
和 HTMLEncode(DocumentMenuClass).Contains("menu-large")
调用的输出。这可能会让您了解为什么没有得到预期的结果。
您的宏看起来正确,但您也可以尝试 this:
When defining conditions or loops, you can leave the body of the
loop/condition open and close it later in another macro expression.
This allows you to apply the command to text content or HTML code
placed between the macro expressions. Open commands can be
particularly useful in macro-based transformations or various types of
HTML templates.
您也可以像文档中的大多数示例一样,尝试在没有 return 语句的情况下重写您的宏。
您只需使用三元运算符并将您的条件放入转换中即可。
{% HTMLEncode(DocumentMenuClass).Contains("menu-large") ? "<ul class='dropdown-menu megamenu'><div class='container megamenu-container'><div class='row'>" : "<ul class='dropdown-menu'>" %}
这应该会按预期工作。
乐于助人
页眉和页脚没有任何页面的上下文,因此您看不到菜单 css 字段。
您想使用第一个项目转换类型,它应该在它的第一个级别上触发。
正如 Trevor 所说,header/footer 转换不代表文档,它们只是显示 before/after 项目转换(代表文档)。
如果您使用项转换来显示菜单项的父项,则可以使用 Prashant 的代码在此处获取 DocumentMenuClass 值。
我使用 Hierarchical Viewer 来构建菜单。我想实现但不知道如何在页眉和页脚转换中执行 If 语句来说明:如果菜单 Class 包含 "menu-large",则显示 abc,否则显示 xyz ,如下所示。我的转型是 Text/XML。感谢您的帮助!
{%
result = "<ul class=\"dropdown-menu\">"; // default value
if(HTMLEncode(DocumentMenuClass).Contains("menu-large")) {result ="<ul class=\"dropdown-menu megamenu\"><div class=\"container megamenu-container\"><div class=\"row\">"}
return result;
#%}
我首先要检查的是 HTMLEncode(DocumentMenuClass)
和 HTMLEncode(DocumentMenuClass).Contains("menu-large")
调用的输出。这可能会让您了解为什么没有得到预期的结果。
您的宏看起来正确,但您也可以尝试 this:
When defining conditions or loops, you can leave the body of the loop/condition open and close it later in another macro expression. This allows you to apply the command to text content or HTML code placed between the macro expressions. Open commands can be particularly useful in macro-based transformations or various types of HTML templates.
您也可以像文档中的大多数示例一样,尝试在没有 return 语句的情况下重写您的宏。
您只需使用三元运算符并将您的条件放入转换中即可。
{% HTMLEncode(DocumentMenuClass).Contains("menu-large") ? "<ul class='dropdown-menu megamenu'><div class='container megamenu-container'><div class='row'>" : "<ul class='dropdown-menu'>" %}
这应该会按预期工作。
乐于助人
页眉和页脚没有任何页面的上下文,因此您看不到菜单 css 字段。
您想使用第一个项目转换类型,它应该在它的第一个级别上触发。
正如 Trevor 所说,header/footer 转换不代表文档,它们只是显示 before/after 项目转换(代表文档)。
如果您使用项转换来显示菜单项的父项,则可以使用 Prashant 的代码在此处获取 DocumentMenuClass 值。