Play! 中的可重用视图框架 2.6.2

Reusable views in Play! Framework 2.6.2

我在将 partial/reusable 视图导入 Play 中的 .scala.html 文件时遇到问题!框架(2.6.2)。

我的可重用组件名为 _enhance。scala.html,位于名为 partials 的文件夹中,其中包含以下模态代码:

@()
<link rel="stylesheet" media="screen" href="@routes.Assets.versioned("css/modal.css")">

<div id="myModal" class="modal">
    <div class="modal-content">
        <span class="close">&times;</span>
        <p>Some text in the Modal..</p>
    </div>
</div>

在另一个视图中,我正在尝试像这样导入它:

@import views.html.partials._enhance

然后像这样使用它:

@_enhance

据我所知,这样做应该会导致模态被导入到我要导入它的页面的 html 中。我没有收到任何错误,但结果显示在我的屏幕上:

BaseScalaTemplate(play.twirl.api.HtmlFormat$@65195b0f)

根据我的理解,这表明屏幕正在呈现对象的字符串。我在这里缺少一点吗?

如有任何建议,我们将不胜感激!

直接尝试@views.html.partials._enhance()(用它替换@_enhance),在这种情况下不需要导入

And then use it like so:

@_enhance

你只是忘记了 ():

@_enhance()

对你有用