获取 Play 框架中父模板使用的变量

发布于 2024-12-14 20:17:52 字数 142 浏览 2 评论 0原文

我想将 main.html 中使用的变量用于所有子模板。

例如,

我在 main.html 中读取了一个名为“ClientID”的属性。这必须在所有继承的 html 模板中使用,而不是再次读取相同的属性。如何在 Play 框架中实现这一点

I want to use a variable which is used in main.html to all the child template.

For Ex,

I read a property called "ClientID" in main.html. This has to be used in all the inherited html templates instead of reading the same property once again. How to achive this in Play framework

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雨后咖啡店 2024-12-21 20:17:52

在 Groovy 模板中,您有一个名为“_caller”的预定义变量,它允许访问模板的调用者变量

${_caller.your_var}

In Groovy Templates, you have a predefined variable called "_caller" which allows to access the template's caller variables

${_caller.your_var}
橘寄 2024-12-21 20:17:52

我能够通过控制器注入 ClientID。但我需要在所有页面中使用该客户端 ID,但我不应该保留在会话或 Cookie 中。这就是为什么我想进入 main.html 并在子模板中使用它。但我通过另一种方式实现了这一点。定义的Play PlugIn,它就像一个ServletFilter。覆盖“beforeActionInspiration”并为所有请求注入 ClientID

I was able to inject ClientID thro Controllers. But I needed that client ID in all the pages But I shouldn't keep in Session or Cookies. Thats why I wanted to get in main.html and use it in child templates. But I achived this in another way. Defined Play PlugIn, its like an ServletFilter. Overidden 'beforeActionInvocation' and injected the ClientID for all th requests

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文