Umbraco - 通过 URL 选择节点 [英] Umbraco - Select node by URL

查看:24
本文介绍了Umbraco - 通过 URL 选择节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试通过节点的 url 访问节点时遇到了 Umbraco 的问题.

I'm having issues with Umbraco when trying to get access to a node by it's url.

我一直在尝试形成一个 xpath 查询以在 url 上进行选择,但我不知道如何做到这一点,而且他们 API 中的所有内容都是动态"的,因此我发现无法挖掘太多内容更深入的其他方法.

I've been trying to form an xpath query to select on the url, but I've no idea how to do that, and everything in their API is a 'dynamic' so I'm finding it impossible to dig much deeper for other methods.

Umbraco 编辑器中的文档链接"属性显示路径为/links/link-regions/link-region-1/".它在编辑器中的位置是/Data/Links/Link Regions/Link Region 1".

The "Link to document" property in the Umbraco editor shows the path to be "/links/link-regions/link-region-1/". Its location in the editor is "/Data/Links/Link Regions/Link Region 1".

我怀疑它看起来像这样,但我无法让它发挥作用:

I suspect it'll look like this, but I cna't make it work:

//*[@url='/links/link-regions/link-region-1/']

我基本上想知道我必须通过提供这些值中的一个而不提供其他值来获取节点.几天来我一直在尝试这样做,但无济于事,请帮忙!

I basically want to know what I have to do to get the node by providing either of these values and no others. I've been trying to do this for days now to no avail, please help!

推荐答案

如果您使用的是 Umbraco 4.11 或更高版本,则有一组新的 API 允许您检索强类型内容(而不是动态 -在调试时尝试评估类型时可能会令人沮丧).

If you're using Umbraco 4.11 or later, there are a new set of APIs that allow you to retrieve strongly-typed content (as opposed to dynamic - which can be frustrating when trying to evaluate types when debugging).

UmbracoContext.Current.ContentCache.GetByRoute(string url) 应该做你想做的.

这篇关于Umbraco - 通过 URL 选择节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆