Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed-issue-6573-Include examples of implicit request in documentation #155

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion docs/manual/working/scalaGuide/main/templates/ScalaTemplates.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ Or even several parameter groups:

@[curried-parameters](code/scalaguide/templates/curriedParameters.scala.html)

### Defining an implicit Requests in Templates

You can define implicit parameters for a template too:

```
@(user: models.User)(implicit requestHeader: RequestHeader, messagesProvider: MessagesProvider)
```

Many template helpers expect an implicit value to be in scope. For example, Cross-Site Request Forgery (CSRF) protection [needs a RequestHeader](ScalaCsrf#Defining-an-implicit-Requests-in-Templates) and Form Helpers [need a MessageProvider](ScalaForms#Passing-MessagesProvider-to-Form-Helpers).

## Template constructor

By default, a template is generated as a static function that can be invoked in any context. If your template has dependencies on components, such as the messages API, you may find it easier to inject it with the components (and other templates) that it needs, and then you can inject that template into the controllers that use it.
Expand Down Expand Up @@ -168,4 +178,4 @@ For example to output raw HTML:

The template engine can be used as a [string interpolator](http://docs.scala-lang.org/overviews/core/string-interpolation.html). You basically trade the “@” for a “$”:

@[string-interpolation](code/ScalaTemplates.scala)
@[string-interpolation](code/ScalaTemplates.scala)