在播放framewrok 2.2 scala模板时读取cookie值 [英] reading cookie value in play framewrok 2.2 scala template

查看:150
本文介绍了在播放framewrok 2.2 scala模板时读取cookie值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试读取播放框架模板内的cookie值(不在控制器内)。我正在尝试以下不工作:

I am trying to read a cookie value inside the play framework template (not inside a controller). I am trying the following which is not working:

@ val cookieVal = request.cookies.get('PLAY_SESSION').value

任何解决此问题的建议都将不胜感激。我试图这样做的原因是改变页面基于cookie值呈现的方式。

Any suggestions to fix this will be greatly appreciated. The reason why I am trying this is to change how the page gets rendered based on a cookie value.

推荐答案

在模板中,您可以定义 val s,如下所示:

In templates you define vals as follows:

@defining(request.cookies.get('PLAY_SESSION').value) { theValue =>
  <div>Hello @theValue</div>
}

我个人更喜欢读取控制器中的cookies并将它们传递给模板如果需要的话。

I personally prefer to read the cookies in the controller and pass them to the template if needed.

这篇关于在播放framewrok 2.2 scala模板时读取cookie值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆