You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Kentico宏中为邮件小部件设置多条件Where子句?

Kentico宏多条件查询正确写法

原单条件查询可正常运行:

style="background-color: {% CMSContext.Current.GlobalObjects.CustomTables["Keyton.EmailTemplateUIElements"].Items.Where("StyleKey = 'theme_bg_1'").FirstItem.StyleValue #%};"

尝试多条件查询时,错误地在Where条件字符串内嵌套宏标签导致语法错误,以下是两种正确写法:

写法1:直接拼接属性值

style="background-color: {% CMSContext.Current.GlobalObjects.CustomTables["Keyton.EmailTemplateUIElements"].Items.Where("StyleKey = 'theme_bg_1' and Theme = '" + Theme + "'").FirstItem.StyleValue #%};"

写法2:用字符串格式化提升可读性

style="background-color: {% 
var condition = string.Format("StyleKey = 'theme_bg_1' and Theme = '{0}'", Theme);
CMSContext.Current.GlobalObjects.CustomTables["Keyton.EmailTemplateUIElements"].Items.Where(condition).FirstItem.StyleValue 
#%};"

关键说明

  • 外层已处于宏解析上下文,无需在Where的条件字符串内再次嵌套{% ... %}标签,直接引用小部件属性Theme即可。
  • 必须用单引号包裹Theme的值,确保它作为字符串参数传入查询条件。

内容的提问来源于stack exchange,提问作者chamara

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 17:22:36