title: Dynamically change (@main) name, in Play Framework 2.2.2 (Scala)
body: <p>I was trying to make the Play layout a bit more dynamic, but didn't know how, any help??</p>
  
  <p>My problem goes like :</p>
  
  <p><strong>index.scala.html</strong></p>
  
  <pre><code>@(title: String,templateName:String) // templateName is data obtained from a db src,  
  
  @templates.(@templateName)(title,templateName){ // I wanted to put value of templateName after @template.****, so that template names get set at compile time, but of course it gives out errors
  }
  </code></pre>
  
  <p>Inside <strong>view</strong> -> <strong>templates</strong> -> <code>main.scala.html</code>, <code>foo.scala.html</code>, <code>bar.scala.html</code> </p>
  
  <p>I am not saying that I need to make the whole 'Main-Layout' dynamically but, just get the names dynamically. Can it be done??</p>
  
  <p>I tried doing it like below, but I will need to know every <code>templates name</code>, any suggestions</p>
  
  <p><strong>index.scala.html</strong></p>
  
  <pre><code>@(title: String,templateName:String)
  
  @if(templateName == "foo"){
      @templates.foo(title,templateName){
      }
  }
  else if(templateName == "bar"){
      @templates.bar(title,templateName){
  } else {
      ......
  }
  </code></pre>
  
  <p>I guess I didn't explain my <strong>issue</strong> properly:</p>
  
  <p>@johanandren 
  Well there seems to be some misunderstanding. Yes I do understand now that I am not allowed to give template name <strong>dynamically</strong> <code>(if reflection isn't used, and it seems to have its own cons as well,thanks to you and @Khanser)</code>from the controller, which I never was planning to do at all.</p>
  
  <p>But like you have said "<strong>If you just want to apply common templating around your individual sub-templates</strong>", my main concern is that I wont have a <strong>common templating</strong>, as you have stated , infact based on the user => different <strong>main template</strong>. Yes I could use the switch/case for my purpose but I'll need to know * template names and hardcode them on each and every sub-template. </p>
  
  <p>And Yes, I have understood the use of "templates->main.scala.html" and "sub-templates=>index.scala.html" etc,etc.... and injecting <strong>sub-templates</strong> on <strong>main templates</strong>. And I think I have already been doing this <code>invert the template flow</code>.</p>