我可以使用 Kentico 宏来获取部分路径吗?
我想知道是否可以使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您正在使用门户模板,并且您不希望在父页面上显示“所有子类别中的所有项目”列表:
Path
设置为/{0}/{1}/{2}/%
(例如,如果您的路径是 /Home/Parent/Subcategory)或其他内容与您的环境类似。继承
。这不会在父页面上显示任何内容,子类别将仅显示其下的文档。注意:如果您希望当用户深入到
/{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:
Path
to/{0}/{1}/{2}/%
(if your path was /Home/Parent/Subcategory for example) or something similar for your environment.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.您可以创建自定义宏,也可以使用宏中允许的字符串操作。请参阅 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