Reusable views in Play! Framework 2.6.2

296 Views Asked by At

I'm having a problem importing a partial/reusable view to a .scala.html file in the Play! Framework (2.6.2).

My reusable component is called _enhance.scala.html, in a folder called partials and has this modal code in it:

@()
<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>

In another view I am trying to import it like so:

@import views.html.partials._enhance

And then use it like so:

@_enhance

In my understanding doing that should result in the modal being imported into the html of the page I'm importing it to. I am not getting any errors, but the result is this showing up on my screen:

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

This suggests the screen is rendering a string of the Object, from my understanding. Is there a bit I'm missing here?

Any advice would be appreciated!

2

There are 2 best solutions below

0
Teimuraz On BEST ANSWER

Try @views.html.partials._enhance() directly (replace @_enhance with it) and you do not need import in this case

0
Andriy Kuba On

And then use it like so:

@_enhance

You just forget the ():

@_enhance()

Will work for you