xdev
xdev

Reputation: 699

play framework call helper function from another template

I have a helper file utils.scala.html which looks like below:

@renderTableRow(columnTag: String, columns: Seq[String]) = {
<tr>
@for(column <- columns) {
    <@columnTag>
        @column
    </@columnTag>
}
</tr>
}

I want to call this helper function from rest of my view files to create table headers.

@import views.html.mycommon.utils

@renderQuotesTable() = {
<table class="table table-bordered table-striped">
  <thead>
       @utils.renderTableRow("th", Seq("Name", "Date of Birth", "Age"))
  </thead>
  <tbody>
  </tbody>

}

But, I get the following the error

value renderTableRow is not a member of object views.html.mycommon.utils.

what am I missing here?

Upvotes: 4

Views: 1662

Answers (1)

Schleichardt
Schleichardt

Reputation: 7542

You cannot import the declared functions of another template. Execute sbt doc and in the generated Scala Doc is no clue of renderTableRow in the util object. "renderTableRow" is wrapped into the apply method as you can see in the generated source for the template: "target/scala-2.10/src_managed/main/views/html/mycommon/utils.template.scala".

For every function you want to use in another template you hava to create a template or a function in a real Scala singleton object.

Upvotes: 1

Related Questions