I was trying to make the Play layout a bit more dynamic, but didn't know how, any help??
My problem goes like :
index.scala.html
@(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
}
Inside view -> templates -> main.scala.html
, foo.scala.html
, bar.scala.html
I am not saying that I need to make the whole 'Main-Layout' dynamically but, just get the names dynamically. Can it be done??
I tried doing it like below, but I will need to know every templates name
, any suggestions
index.scala.html
@(title: String,templateName:String)
@if(templateName == "foo"){
@templates.foo(title,templateName){
}
}
else if(templateName == "bar"){
@templates.bar(title,templateName){
} else {
......
}
I guess I didn't explain my issue properly:
@johanandren
Well there seems to be some misunderstanding. Yes I do understand now that I am not allowed to give template name dynamically (if reflection isn't used, and it seems to have its own cons as well,thanks to you and @Khanser)
from the controller, which I never was planning to do at all.
But like you have said "If you just want to apply common templating around your individual sub-templates", my main concern is that I wont have a common templating, as you have stated , infact based on the user => different main template. 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.
And Yes, I have understood the use of "templates->main.scala.html" and "sub-templates=>index.scala.html" etc,etc.... and injecting sub-templates on main templates. And I think I have already been doing this invert the template flow
.