[2.0] Multiple Html parameters in a scala template

4,390 views
Skip to first unread message

Josh

unread,
Mar 7, 2012, 11:34:52 PM3/7/12
to play-fr...@googlegroups.com
Please pardon me if I should have looked harder, but I searched the docs and can't find an example of this problem. 

I've modified the sample main.scala.html to take an extra parameter (see the bottom of this message, note the additional 'extra_scripts' parameter), but I can't figure out how to use it... No matter what I try, I get the error message:

"missing arguments for method apply in object main; follow this method with `_' if you want to treat it as a partially applied function"

with something like this:

@main("My Page") {
     <!-- script Html here -->
}
{
     <!-- content Html here -->
}

I'm sure this is brain dead simple, but the docs don't seem to cover it.


@(title: String)(extra_scripts: Html)(content: Html)

<!DOCTYPE html>

<html>
    <head>
        <title>@title</title>
        <link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/main.css")">
        <link rel="shortcut icon" type="image/png" href="@routes.Assets.at("images/favicon.png")">
        <script src="@routes.Assets.at("javascripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
        @custom_scripts
    </head>
    <body>
        @content
    </body>
</html>

Marcos Pereira

unread,
Mar 8, 2012, 12:48:17 AM3/8/12
to play-fr...@googlegroups.com
The docs cover it:

https://github.com/playframework/Play20/wiki/JavaTemplateUseCases

HTH
--
http://about.me/marcospereira


--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To view this discussion on the web visit https://groups.google.com/d/msg/play-framework/-/R-UEBJzaZvUJ.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.

Guillaume Bort

unread,
Mar 8, 2012, 7:53:48 AM3/8/12
to play-fr...@googlegroups.com
Just put } { on the same line.

> --
> You received this message because you are subscribed to the Google Groups
> "play-framework" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/play-framework/-/R-UEBJzaZvUJ.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to
> play-framewor...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/play-framework?hl=en.

--
Guillaume Bort

Josh

unread,
Mar 8, 2012, 9:26:01 AM3/8/12
to play-fr...@googlegroups.com
Sorry I missed that, thanks. I could have sworn I tried that but I did figure out an alternative:

@scripts = {
    // extra scripts
}

@main("Translations")(scripts){
    // main body
To post to this group, send email to play-framework@googlegroups.com.
To unsubscribe from this group, send email to play-framework+unsubscribe@googlegroups.com.

Josh

unread,
Mar 8, 2012, 10:15:59 AM3/8/12
to play-fr...@googlegroups.com
Is there any way to make a _middle_ parameter optional? Or should I move extra_scripts to the end of the parameter call if I won't be needing it on most pages?

For now, on pages that don't need extra scripts I tried an empty block, like this:

@main("Translations") {} {

but I get this error message:

type mismatch; found : Unit required: play.api.templates.Html

So I've worked around it like this:

@main("Translations") {&nbsp;} {

I'm pretty sure that isn't best practice, but since I'm new to scala, I'm not sure what a better solution would be.

I hope this gets indexed and helps some other newbie who might come along... 

Zoro

unread,
Mar 19, 2012, 4:09:06 PM3/19/12
to play-framework
Josh, thanks, It was very helpful for me. As it is written in the
documentation (a reference to that provided Marcos Pereira), which was
updated 5 days ago, you can set the default value for extra_scripts,
and combine the first two parameters into a single group.

@(title: String, extra_scripts: Html = Html(""))(content: Html)

So, you will need write:

@main("My Page")
{
<!-- content Html here -->
}

And the extra_scripts will have a default value.

By the way. Documentation on the official website does not contain a
paragraph "Documentation on the official website does not contain a
paragraph".
> >>> To post to this group, send email to play-fr...@googlegroups.com.
> >>> To unsubscribe from this group, send email to
> >>> play-framewor...@googlegroups.com.

Zoro

unread,
Mar 19, 2012, 4:11:52 PM3/19/12
to play-framework
Sorry. I accidentally changed the subject of discussion. I do not know
how I did it. =(

Zoro

unread,
Mar 19, 2012, 4:16:53 PM3/19/12
to play-framework
I wanted to say "moreScripts and moreStyles equivalents" paragraph..
not inserted.

On Mar 20, 12:09 am, Zoro <khandra...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages