我可以使用 Kentico 宏来获取部分路径吗?

发布于 2024-12-19 15:07:04 字数 271 浏览 2 评论 0原文

我想知道是否可以使用 kentico 宏(不一定要编写自定义宏)来访问重写的 URL 路径的一部分。

示例: http://www.mysite.com/Category/Subcategory/

我想获取最后一部分(子类别),以便我可以动态过滤内容。我想使用宏的原因是不必仅拥有 20 多个不同的页面模板,这样我就可以拥有不同的 Web 部件属性。

I would like to know if it is possible to use kentico macros (not necessarily coding a custom one) to access part of the rewritten URL's Path.

Example: http://www.mysite.com/Category/Subcategory/

I would like to get the last part (Subcategory) so that I may then filter content dynamically. The reason I want to use the macro is to simply not have to have 20+ different page templates only so I can have different web part properties.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柠檬 2024-12-26 15:07:04

假设您正在使用门户模板,并且您不希望在父页面上显示“所有子类别中的所有项目”列表:

  1. 在父页面上创建文章列表 Web 部件 - 所有子类别的父页面。
  2. 将 Web 部件 Path 设置为 /{0}/{1}/{2}/%(例如,如果您的路径是 /Home/Parent/Subcategory)或其他内容与您的环境类似。
  3. 对所有子类别页面的页面模板使用默认设置继承

这不会在父页面上显示任何内容,子类别将仅显示其下的文档。注意:如果您希望当用户深入到 /{0}/{1}/{2}/item 时子类别项目有自己的视图,您可能需要通过更改模板继承来进行过滤,或 Web 部件上的文档类型,或者类似的内容(如果您不希望整个子类别列表也显示在特定于项目的页面上)。

Assuming you are using Portal templates, and you don't want an 'all items in all subcategories' list on the parent:

  1. Create an Article List web part on the parent page — parent to all the sub-categories.
  2. Set the web part Path to /{0}/{1}/{2}/% (if your path was /Home/Parent/Subcategory for example) or something similar for your environment.
  3. Use the default setting of Inherit for the page template for all subcategory pages.

This will not show anything on the parent page, and the sub-categories will show only the documents under themselves. Note: If you want the subcategory items to have their own views when user digs down to /{0}/{1}/{2}/item, you may need to filter by changing template inheritance, or Document Types on the web part, or something like that if you don't want the whole sub-category list to also show on the item-specific pages.

风向决定发型 2024-12-26 15:07:04

您可以创建自定义宏,也可以使用宏中允许的字符串操作。请参阅 http://devnet.kentico.com/docs/6_0/devguide /available_macro_methods.htm#string_methods (您可以使用 EndsWith 或 TrimStrart 等 相似的)。

但是,我认为最好的方法是创建一个完全适合的自定义宏。可能存在宏和宏函数的某种组合 - 但我认为编写一个自定义的代码会更快,它将 100% 满足您的需求。

另外,您可以查看 K# 是否有适合的内容 - http://devnet.kentico.com/docs/6_0/devguide/ksharp_syntax.htm

You can create a custom macro or, you can also use the string operations which are allowed within macros. Please see http://devnet.kentico.com/docs/6_0/devguide/available_macro_methods.htm#string_methods (and you can e.g. use the EndsWith or TrimStrart or something similar).

However, I think the best way would be to create a custom macro which will exactly fit. There might be some combination of macros and macro functions - but I think it is faster just to code a custom one which will cover your need 100%.

Also, you can take a look on the K# if there is something that will fit - http://devnet.kentico.com/docs/6_0/devguide/ksharp_syntax.htm

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文