How to pass raw html to Play framework view?

前端 未结 2 1586
眼角桃花
眼角桃花 2021-02-04 01:11

I\'m trying to pass a simple URL to a view within a play framework app, however when passed as a string, the & in the url is changed to & w

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-04 01:55

    To prevent the default escaping that happens for dynamic content on views you need to wrap the String with @Html(String) function:

    View:

    @(url: String)
    
    

    Controller:

    public static Result displayLink(){
       return ok(view.render("Stack Overflow"));
    }
    

    See The template engine page on the documentation for more info (specifically the "Escaping" section at the very bottom).

提交回复
热议问题