开发者

In (Scala) Lift, how to render the original HTML from the template when using Helpers.bind

I'm a Scala/Lift beginner and I'm having trouble with rendering a list with optional "tags" on each item.

My HTML template says

<lift:Items.list>
  <e:name>Rock</e:name><br />
  <e:warning><span style="color:#ff0000;">DANGER!</span></e:warning>
</lift:Items.list>

And on the Items.scala开发者_如何学JAVA I have

def list(node : NodeSeq) : NodeSeq = {

  getItems flatMap( it => {

     Helpers.bind("e", node,
                  "name" -> { Text(it.name) },
                  "warning" -> { 
                      if (it.isDangerous) { <<INSERT HTML FROM TEMPLATE>> } 
                      else { Text("") }
                         }
                  )
  })
}

I'd like to, in certain cases, have the contents of the "e:warning" tag rendered verbatim. I'm sure there's an easy way to extract them from "node", but I guess I have some major gaps in my Lift knowledge because I can't figure out how. If anyone could point out the proper procedure to me I'd be very thankful.


ANSWERED: Thanks for the advice. I ended up structuring my code like this:

    "warning" -> { (n : NodeSeq) => {
                  if (it.isDangerous) { n } else { Text("") }
                 }}


You can simply bind a function to the node’s name which takes a NodeSeq and returns a NodeSeq.

E.g.:

def warning(in: NodeSeq): NodeSeq = doSomethingWith(in)

// ...

Helpers.bind("e", node, "warning" -> warning _)

The contents of the <e:warning> node will then be transformed and inserted.


I'm not sure on the purpose of what you are trying to do. If you want to display one thing or the other, use chooseTemplate and a Box.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜