我有模板和两个片段。我可以在模板中获取用于选择动态代码段的ID。
def remote =
Menu.param[Point]("Test1", "remote",
id => inTransaction(Points.lookup(id)), _.id) / "point" / * / "remote" >>
//inTransaction(Points.lookup(id)) match
// case point.Kind.remote =>
Loc.Template(() => Templates("point" :: "remote" :: Nil).openOr(Nil)) >> Hidden
// case point.Kind.otherremote =>
//Loc.Template(() => Templates("point" :: "otherremote" :: Nil).openOr(Nil)) >> Hidden
答案 0 :(得分:2)
您应该使用ValueTemplate
代替,它提供当前解析的值为参数。
以下代码未经测试,但您应该明白这一点:
def remote = Menu.param[Point]("Test1", "remote",
id => inTransaction(Points.lookup(id)), _.id) / "point" / * / "remote" >>
Loc.ValueTemplate(point => point match
case Full(p) if p.Kind.remote => Templates("point" :: "remote" :: Nil).openOr(Nil))
case Full(p) if p.Kind.otherremote => Templates("point" :: "otherremote" :: Nil).openOr(Nil))
case _ => NodeSeq.Empty
) >> Hidden