title: Scala/Twirl variables and scope/defining
body: <p>I'm a front ender by trade but I've been asked to hop on to a Scala project which leverages the Play framework so includes Twirl.  I'm trying to create a template which displays slightly different outputs depending on the string which is passed in.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>@(status: String)(implicit messages: Messages)
  
  @{
      if(status == "00") {
          val pageTitle = "Page title"
          val appStatus = "className"
          val title = "message"
          val subTitle = "message"
          val step1Status = "className"
          val step2Status = "className"
          val step3Status = "className"
          val image1 = "/customs/assets/images/image.png"
          val image2 = "/customs/assets/images/image.png"
          val image3 = "/customs/assets/images/image.png"
          val optionalHeading = ""
          val optionalParagraph = ""
          val listContents = "&lt;li&gt;@Messages('message')&lt;/li&gt;&lt;li&gt;@Messages('message')&lt;/li&gt;"
          val optionalLink = "&lt;br /&gt;&lt;a class='button' href='@routes.DashboardController.display(custom)' role='button'&gt;@Messages('message')&lt;/a&gt;"
      }
  
      if(status == "01") {
          //Other variables
      }
      if(status == "04") {
          //Etc...
      }
  }
  
  @layout(${pageTitle}) {
          &lt;div class="content__body"&gt;
              &lt;div class="hero"&gt;
                  &lt;div class="${appStatus}"&gt;
                      &lt;h1 class="bold-large"&gt;@Messages(${title})&lt;/h1&gt;
                      &lt;p&gt;
                          ${afterSubTitle}
                      &lt;/p&gt;
                      &lt;ol class="appstatus-steps"&gt;
                          &lt;li&gt;&lt;span class="${step1Status}"&gt;&lt;img alt="Complete" title="Complete" src=" + ${image1} + "&gt;@Messages("messages.Received")&lt;/span&gt;&lt;/li&gt;
                          &lt;li&gt;&lt;span class="${step2Status}"&gt;&lt;img alt="Complete" title="Complete" src=" + ${image2} + "&gt;@Messages("messages.Processing")&lt;/span&gt;&lt;/li&gt;
                          &lt;li&gt;&lt;span class="${step3Status}"&gt;&lt;img alt="Complete" title="Complete" src=" + ${image3} + "&gt;@Messages("messages.Decision")&lt;/span&gt;&lt;/li&gt;
                      &lt;/ol&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
  
              ${optionalHeading}
              ${optionalParagraph}
  
              &lt;h2&gt;@Messages("messages.next")&lt;/h2&gt;
  
              &lt;ul class="list list-bullet"&gt;
                  ${listContents}
              &lt;/ul&gt;
  
              ${optionalLink}
          &lt;/div&gt;
      }
  </code></pre>
  
  <p>So, as you can see, the idea is that this page is called with a code (status) and based on that string, a number of variables are defined which alter the way the page is formed; content/css classes/images etc.</p>
  
  <p>This doesn't work (you may be surprised to learn!)</p>
  
  <p>It's really unclear to me WHY it doesn't though.  I thought that you accessed variables using a ${Variable} format, but it's possible that you're supposed to use the @Variable format instead.</p>
  
  <p>Even when I try to change them to the @Variable way, I'm still getting problems and I loosely understand that this is to do with scope in Scala/Twirl and there's a "defining" keyword which can be used.  I've read some documentation but I'm not getting it.</p>
  
  <p>Could anyone shed some light on this?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Okay, let's just consider the below code instead:</p>
  
  <pre><code>@(status: String)(implicit messages: Messages)
  
  @{
      if(status == "00") {
          val myClass = "custom-class-1"
      }
      if (status == "01") {
          val myClass = "custom-class-2"
      }
  @layout("page title") {
      &lt;div class="@myClass"&gt;This is a div&lt;/div&gt;
  }
  </code></pre>
  
  <p>So 'all I want to do' :) is be able to define a variety of variables based on the status and then use those variables in the template of the page.</p>
  
  <p>Does that make sense?  I'm so new to Scala so Tuples/Defining is lost on me at the moment, but I am learning!</p>