查找带标签的页面

时间:2016-02-29 22:14:43

标签: umbraco umbraco7

在Umbraco 7解决方案中,我在所有页面上都有一个标签内容选择器。页面可以使用此标记在每个页面上设置标记。

然后,我希望在服装网站内获取翻页,其中包含标签111(id,而不是名称)。

我尝试过:

var ids = Model.MacroParameters["tags"]; //the tags to show
CurrentPage.AncestorOrSelf(1).Descendants().Where(x => ids.Contains(x.tags.ToString()));

但这给了我错误:

Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type

什么是正确的方法?

3 个答案:

答案 0 :(得分:1)

解决了它;

Umbraco.Content(rootId).Descendants().Where("tags.Contains(@0)", ids);

答案 1 :(得分:1)

您有几个选项,具体取决于您是喜欢动态还是强类型视图模型。

强类型API

Umbraco.TypedContentAtRoot().Descendants().Where(x => x.tags.Contains(ids));

动态API

Umbraco.ContentAtRoot().Descendants().Where("tags.Contains(@0)", ids);

请注意, Contains 语句可能会给您不一致的结果,因为标记属性似乎返回以逗号分隔的列表。在这种情况下,您可以尝试拆分字符串或安装Core Property Value Converters package并将标记设为IEnumerable<IPublishedContent>

答案 2 :(得分:0)

始终尽量避免使用Descendants,尤其是在根节点上。 获取属性的标记:

ApplicationContext.Current.Services.TagService.GetTagsForProperty(Model.Content.Id, "propertyname")

要查找具有特定标记的内容:

ApplicationContext.Current.Services.TagService.GetTaggedContentByTag("tag")