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 6744083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:02:29+00:00 2026-05-26T12:02:29+00:00

There isn’t much documentation about Play 2.0 template engine. How does one create a

  • 0

There isn’t much documentation about Play 2.0 template engine.

How does one create a tag using Scala template?

  • 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-05-26T12:02:29+00:00Added an answer on May 26, 2026 at 12:02 pm

    The template engine in play 2.0 is directly coming from the play 1.0 scala module. If you are still wondering what benefits does a functional language such as Scala brings to the picture, well this is certainly one of the areas where it shines.

    Demonstration:

    In scala syntax a tag is nothing else than a function call. what’s interesting, is that html fragments are considered as functions themselves, allowing the most powerful substitution constructs.

    Let’s define an html page called mytag.scala.html

    file:apps/views/mytags/mytag.scala.html

    @(level:String = "error", index: Int)(body: (String) => Html)
    
    @level match {
    
        case "success" => {
            <p class="success" index="@index">
                @body("green")
            </p>
        }
    
        case "warning" => {
            <p class="warning" index="@index">
                @body("orange")
            </p>
        }
    
        case "error" => {
            <p class="error" index="@index">
                @body("red")
            </p>
        }    
    }
    

    The tag above takes 3 parameters in 2 distinct parameter groups:

    1. A level, represented by a string ( which defaults to “error”)
    2. An index
    3. Finally a function called body, that takes a string parameter and returns HTML code. Note that body is defined in its own parameter group. it is equivalent to what we know in j2ee as a jsp fragment.

    Now let’s see how we can use this tag:

    @import views.mytags._
    
    @mytag("error",2) { color =>
        Oops, something is <span style="color:@color">wrong</span>
    }
    

    Before we can use a tag (or function), we need to let Play know where it is located: that’s the purpose of the import statement. Note that the location (the path) of the tag file is irrelevant as long as you adjust the import location, just like with Java packages.

    Follows the call itself which is kind of straightforward. Note however that we are passing a parametrized html fragment to the tag.

    For further details, you may find the scala template documentation at this URL

    Play 2.0 will eventually come with its own documentation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There isn't much documentation on the website http://dbdeploy.com/ regarding using the exe version of
There isn't much tutorial in the Pro Drupal book about ahah, but I'm trying
I'm writing a plugin for Confluence and there isn't much documentation on what you
How to add a vmethod to template toolkit when using Dancer? If there isn't
I'm using ASP.NET Membership and noticed there isn't a method in the Roles class
I'm new to ReSharper and am surprised that there isn't a template defined for
I've been using the search function but I think there isn't any related question
I know there is a question about that, but there isn't any good answer(for
I haven't found an answer to this particular question; perhaps there isn't one. But
I'm confused about this. Most of us have been told that there isn't any

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.