Skip to content

Commit

Permalink
Include examples of implicit request in documentation
Browse files Browse the repository at this point in the history
Fixes #6573
  • Loading branch information
Shruti9520 committed Oct 5, 2017
1 parent 1b34f82 commit 958d66a
Showing 1 changed file with 11 additions and 1 deletion.
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)

0 comments on commit 958d66a

Please sign in to comment.