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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:13:25+00:00 2026-06-07T06:13:25+00:00

i want to render to my template 2 things at the same time like

  • 0

i want to render to my template 2 things at the same time like this:

String one = "one"; 
String two = "two";
return ok(template.render(one,two));

but Playframework says, it is wrong. how is it possible to render 2 values at the same time then? should i save them into a list? but then i have to unpack it again in my template.. 🙁

please help! appreciate any help!

  • 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-07T06:13:26+00:00Added an answer on June 7, 2026 at 6:13 am

    Play templates in 2.0 are just Scala functions, so you need to declare params at the beginning of the template (beginning from line #1):

    @(one: String, two: String)
    
    This is first param: @one <br/>
    This is second param: @two
    

    Check the templates docs for details

    Map

    On the other way if you need to pass large quantity of variables of the same type then the Map can be good solution as well:

    public static Result index() {
    
        Map<String, String> labels = new HashMap<String, String>();
    
        labels.put("first", "First label");
        labels.put("second", "Second label");
        // etc etc
        labels.put("hundredth", "Label no. 100");
    
        return ok(template.render(labels));
    }
    

    template.scala.html

    @(labels: Map[String, String])
    
    @labels.get("first") <br/>
    @labels.get("second") <br/>
    .....
    @labels.get("hundredth")
    

    View model

    Finally to make things even more typesafe you can create your own view models like (sample):

    package models.view;
    
    import java.util.Date;
    
    public class MyViewModel {
    
        public String pageTitle = "";
        public Date currentDate = new Date();
        public Integer counter = 0;
        // etc...
    
    }
    

    controller:

    public static Result myActionUsingModel() {
        MyViewModel data = new MyViewModel();
        data.pageTitle = "Ellou' World!";
        data.counter = 123;
    
        return ok(myViewUsingModel.render(data));
    }
    

    view:

    @(data: models.view.MyViewModel)
    
    <h1>@data.pageTitle</h1>
    
    <div>Now is: @data.currentDate</div>
    <div>The counter value is: @data.counter</div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to render same template on one page which should display the value
Well I want to render a self closing tag say <img> tag like this
i want to render one of these sets of views: head body-$id1 foot OR
Currently I have a view which I render to a template and return it
I have a workflow where I need to render an exception page. But this
I have two template files. One is a twig template and another is a
I want to create a reusable template (almost like a UserControl from the .NET
I'm trying, in a template, to include another one that is in the same
I want to render the partial view using ajax. When I submit the button,
I want to render a profile user container that contains a list of labels

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.