是否可以使用自定义类型属性的内容创建一个果园自动布线? [英] Is it possible to create an orchard autoroute using contents of a custom type property?
问题描述
我有一个Orchard cms模块,并设置了一些其他内容类型,并通过代码添加了一个AutoRoute组件。
一切都很完美,但是我对默认的永久模式不满意。
我想做的是添加一个自定义模式,我的内容类型中的公共属性。在我的例子中,自定义类型有一个名为ClubName的公共属性,我希望使用它(从路由角度来看更有意义)。
Orchard部分类名称为 TrackPart
。
我尝试了 {Content.TrackPart.ClubName}
code> {Content.Track.ClubName} , {ContentItem.TrackPart.ClubName}
, {Content。 TrackPart.ClubName}
和各种其他变体,但似乎没有什么工作。
我真的很喜欢Orchard,所以很有可能我缺少一些简单的东西。
任何帮助将非常感激。 >
响应@ Bertrand-le-roy的反馈,我通过复制示例令牌创建了自己的令牌。我现在可以看到下拉菜单中的令牌并选择它。但是路由模式仍然不工作。
我只能假设我误解了Evaluate()函数的 context.For
使用。看起来我没有得到我需要的数据
这是我到目前为止所有的。
code> public class TrackPartTokens:ITokenProvider {
private readonly IContentManager _contentManager;
public TrackPartTokens(IContentManager contentManager) {
_contentManager = contentManager;
}
public Localizer T {get;组; }
public void描述(动态上下文){
context.For(Track,T(Track),T(Tokens for Track))
。令牌(ClubName,T(ClubName),T(俱乐部的名称))
;
}
public void评估(动态上下文){
context.For< TrackPart>(Track)
.Token(ClubName,(Func< TrackPart,object>)(field => field.ClubName))
.Chain(ClubName,ClubName,(Func< TrackPart,object>) $ b;
}< / code>
上述代码基于Orchard.Fields模块中的DateTimeField标记。
context.For(DateTimeField)
.Token(Date,(Func)(field => field.DateTime))
.Chain ,Date,(Func)(field => field.DateTime));
>你必须制作自己的令牌。这真的很容易。复制工作示例。
I have an Orchard cms module with some additional Content types set up and have added an AutoRoute component via code. Everything works perfectly, however I am not happy with the default permalink pattern.
What I am trying to do is add a custom pattern and use one of the public properties in my content type. In my case the custom type has a public property called ClubName and I would like that to be used (It makes more sense from a routing perspective).
The Orchard part class name is called TrackPart
.
I have tried {Content.TrackPart.ClubName}
, {Content.Track.ClubName}
, {ContentItem.TrackPart.ClubName}
,{Content.TrackPart.ClubName}
and various other variations but nothing seems to be working.
I am really new to Orchard so there is a high chance I am missing something simple.
Any help would be greatly appreciated.
In response to feedback from @Bertrand-le-roy I created my own token by copying an example token. I can now get see the token in the drop down menu and select it. However the route pattern is still not working.
I can only assume that I have misunderstood the Evaluate() function's context.For
usage. It looks like I am not getting the data I need
Here is what I have so far.
public class TrackPartTokens : ITokenProvider {
private readonly IContentManager _contentManager;
public TrackPartTokens(IContentManager contentManager) {
_contentManager = contentManager;
}
public Localizer T { get; set; }
public void Describe(dynamic context) {
context.For("Track", T("Track"), T("Tokens for Track"))
.Token("ClubName", T("ClubName"), T("The name of the club."))
;
}
public void Evaluate(dynamic context) {
context.For<TrackPart>("Track")
.Token("ClubName", (Func<TrackPart, object>)(field => field.ClubName))
.Chain("ClubName", "ClubName", (Func<TrackPart, object>)(field =>field.ClubName))
;
}</code>
The above code was based on the DateTimeField token inside the Orchard.Fields module.
context.For("DateTimeField") .Token("Date", (Func)(field => field.DateTime)) .Chain("Date", "Date", (Func)(field => field.DateTime));
You'll have to make your own token. It's really easy. Copy a working example.
这篇关于是否可以使用自定义类型属性的内容创建一个果园自动布线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!