简体   繁体   English

IntelliJ IDEA中的代码辅助,用于Twirl模板中的隐式变量

[英]Code assistance in IntelliJ IDEA for implicit variables in Twirl Template

I am building a web app in Java using the Play! 我正在使用Play在Java中构建Web应用程序! framework and Twirl template engine, using IntelliJ IDEA. 框架和Twirl模板引擎,使用IntelliJ IDEA。 In the template there are a number of implicit variables which are available(flash, session, requestHeader). 在模板中,有许多可用的隐式变量(闪存,会话,requestHeader)。 I can successfully reference any of these variables and my app will compile and run as expected. 我可以成功引用任何这些变量,并且我的应用程序将按预期编译并运行。 However, as these variables have not been explicitly declared, IDEA shows an error(eg. Cannot resolve symbol flash) and does not provide any code assistance. 但是,由于尚未明确声明这些变量,因此IDEA显示错误(例如,无法解析符号闪烁),并且不提供任何代码帮助。 While it is not a huge problem I would like to fix this if possible. 尽管这不是一个大问题,但我想尽可能解决此问题。

I have searched quite a bit for a solution, and the JetBrains blog has a post on how to do this for Velocity templates, if someone could help me do the same for Twirl templates I would be very thankful! 我已经搜索了很多解决方案,并且JetBrains博客上有一篇关于如何对Velocity模板执行此操作的帖子,如果有人可以帮助我对Twirl模板做同样的事情,我将非常感谢!

Jackson 杰克逊

I have found a solution to this problem, which is to refer to the fully qualified name within the code, ie. 我找到了解决此问题的方法,即在代码中引用标准名称,即。 to access the flash variable use 访问flash变量使用

@play.mvc.Http.Context.Implicit.flash

This can also be imported at the top of a template, then you can simply refer to @flash in the code. 也可以将其导入模板的顶部,然后只需在代码中引用@flash。

This should not be necessary- Play! 这不是必须的-玩! is aware of these variables without explicitly importing them, this is simply for IDEA's sake. 知道这些变量而没有显式导入它们,这只是出于IDEA的缘故。 Strangely enough, I found that after creating a new project through IDEA it actually did provide the expected behaviour- I could simply use @flash without the import and IDEA would work as expected. 奇怪的是,我发现通过IDEA创建新项目后,它确实提供了预期的行为-我可以简单地使用@flash而无需导入,IDEA可以按预期工作。 However once I closed and reopened the project the same problem would occur. 但是,一旦我关闭并重新打开该项目,就会出现相同的问题。

At the moment this is the best solution I have found, although I have contacted IntelliJ support and if they offer a better solution I will update my answer accordingly. 目前,这是我找到的最佳解决方案,尽管我已与IntelliJ支持人员联系,如果他们提供了更好的解决方案,我将相应地更新我的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM