Skip to content

Commit 958d66a

Browse files
committed
Include examples of implicit request in documentation
Fixes #6573
1 parent 1b34f82 commit 958d66a

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

docs/manual/working/scalaGuide/main/templates/ScalaTemplates.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ Or even several parameter groups:
8484
8585
@[curried-parameters](code/scalaguide/templates/curriedParameters.scala.html)
8686
87+
### Defining an implicit Requests in Templates
88+
89+
You can define implicit parameters for a template too:
90+
91+
```
92+
@(user: models.User)(implicit requestHeader: RequestHeader, messagesProvider: MessagesProvider)
93+
```
94+
95+
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).
96+
8797
## Template constructor
8898
8999
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.
@@ -168,4 +178,4 @@ For example to output raw HTML:
168178

169179
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 “$”:
170180

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

0 commit comments

Comments
 (0)