Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8993907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:18:05+00:00 2026-06-15T23:18:05+00:00

The Play Framework 2 template language is pretty nice. However, though it’s ‘inspired by’

  • 0

The Play Framework 2 template language is pretty nice. However, though it’s ‘inspired by’ Microsoft’s Razor language, one important design decision is different: how you ‘escape back’ into HTML. Razor looks for HTML-style tags and Play 2 uses some kind of heuristic.

I’m trying to write a template which takes multiple ‘sections’ of HTML, and generates a page with headers and a table of contents. My ‘structuredpage.scala.html’ looks like this:

@(title: String)(sections: Pair[String,Html]*)

@main(title){
    <nav class="page-links">
        @makeTableOfContents(sections)
    </nav>
    @for(section <- sections){
        <section id="@section._1">
            <h2>@section._1</h2>
            @section._2
        </section>
    }
}

Note that its second parameter is a variable number of sections. There does not seem to be a way of calling this in the Play templating language.

I’ve created a helper function called Common.section which looks like this:

    def section(title: String)(content: Html) = title -> content;

I’ve tried this:

@()
@import views.Common.section

@structuredpage("Dashboard")(
    section("Latest Requests") {
        <p>Blah</p>
    },
    section("Your Details") {
        <p>Blah blah</p>
    }
)

…which gives type mismatch; found : scala.xml.Elem required: play.api.templates.Html on line 5, i.e., <p>Blah</p> is being interpreted as Scala, not as template document HTML.

And this:

@()
@import views.Common.section

@structuredpage("Dashboard"){
    @section("Latest Requests") {
        <p>Blah</p>
    },
    @section("Your Details") {
        <p>Blah blah</p>
    }
}

…which gives type mismatch; found : play.api.templates.Html required: (String, play.api.templates.Html) on line 3, i.e., the entire outer curley-brace block is being interpreted as template document HTML, not as Scala code!

Frustratingly they don’t seem to be hugely different than some code samples in the official Play 2 documentation, for example: http://www.playframework.org/documentation/2.0/ScalaTemplateUseCases

Any ideas? I’m using Play Framework 2.0.4

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:18:06+00:00Added an answer on June 15, 2026 at 11:18 pm

    Here’s what you might be looking for. It’s not exactly FP though

    structuredpage.scala.html

    @(title: String)(content: scala.collection.mutable.MutableList[Pair[String, Html]] => Unit)
    
    @main(title){
        @defining(new scala.collection.mutable.MutableList[Pair[String,Html]]()) { sections =>
            @content(sections)
            @for(section <- sections){
                <section id="@section._1">
                    <h2>@section._1</h2>
                    @section._2
                </section>
            }
        }
    }
    

    frontpage.scala.html

    @()
    
    @import views.Common.section
    
    @structuredpage("Front Page") { implicit sections =>
        @section("Section 1") {
            <h1>stuff</h1>
        }
    
        @section("Section 2") {
            <h1>more stuff</h1>
        }
    }
    

    section method:

    def section(title: String)(content: Html)(implicit sections: scala.collection.mutable.MutableList[Pair[String, Html]]) {
        sections += title -> content
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JSON template under app/views/Application/movie.json in my Play Framework app. Normally you
I am using the following template tag in the Play framework to create an
I have come from using the Play! Framework where putting links in a template
Possible Duplicate: Calculation in Play 2.0 Framework template engine If I have some view
I am finding difficult to display the template in play framework using groovy #{list
I want to include some LaTEX code in play framework 2.0 template, namely: \usepackage[T1]{fontenc}
In Play Framework , Can one use the #{extends} tag recursively? I.e., in a
Rythm is a template engine for Play ! framework views. It is type safe
How to create an inline variable in the Play framework 2.x Scala template? Path
play framework: 1.2.3 Hi, I am trying to purge my database by using play's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.