From 958d66a6a580c8b72f72a37c44fc067ac4e01405 Mon Sep 17 00:00:00 2001 From: Shruti9520 Date: Mon, 2 Oct 2017 16:48:48 +0530 Subject: [PATCH] Include examples of implicit request in documentation Fixes #6573 --- .../scalaGuide/main/templates/ScalaTemplates.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/manual/working/scalaGuide/main/templates/ScalaTemplates.md b/docs/manual/working/scalaGuide/main/templates/ScalaTemplates.md index 536153b8..b0310d45 100644 --- a/docs/manual/working/scalaGuide/main/templates/ScalaTemplates.md +++ b/docs/manual/working/scalaGuide/main/templates/ScalaTemplates.md @@ -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. @@ -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) \ No newline at end of file +@[string-interpolation](code/ScalaTemplates.scala)