我有模板和两个片段。我可以在模板中获取 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
最佳答案
您应该使用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
关于scala - LiftWeb Loc.Template 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9258275/