Skip to content

Commit c2263ee

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

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

docs/manual/working/javaGuide/main/templates/JavaTemplates.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ Or even several parameter groups:
110110
```scala
111111
@(title:String)(body: Html)
112112
```
113+
### Defining an implicit Requests in Templates
114+
115+
You can define implicit parameters for a template too:
116+
117+
```
118+
@(user: models.User)(implicit requestHeader: RequestHeader, messagesProvider: MessagesProvider)
119+
```
120+
121+
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).
113122

114123
## Template constructor
115124

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)