Search code examples
javascripttemplatesscalarenderinglift

How do we use net.liftweb.http.js.JsCmds.Script object in lift?


I am porting a legacy system from rails into lift. It has a lot of hard-coded concatenated javascript that I would like to render into html pages.

According to this conversation here, we can use net.liftweb.http.js.JsCmds.Script object this way:

Script("""
var x = "Here's my JavaScript & it looks good";
""")

However, I got this compiler message:

error: type mismatch;
[INFO]  found   : java.lang.String
[INFO]  required: net.liftweb.http.js.JsCmd

What is the correct way to use net.liftweb.http.js.JsCmds.Script?


Solution

  • Well, the conversation is clearly wrong.

    The apply method for net.liftweb.http.js.JsCmds.Script takes a JsCmd as a parameter - that's the source of your compiler error.

    Now for that specific case, you could fix it to something like this:

    Script(JsCrVar("x", new Str("Here's my JavaScript & it looks good")))
    

    (Str is net.liftweb.http.js.JE.Str)