Play レイアウトをもう少し動的にしようとしていましたが、方法がわかりませんでした。
私の問題は次のようになります:
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
}
内部ビュー->テンプレート-> main.scala.html
、foo.scala.html
、bar.scala.html
「Main-Layout」全体を動的に作成する必要があると言っているわけではありませんが、名前を動的に取得するだけです。それはできますか??
templates name
以下のようにしてみましたが、すべての提案を知る必要があります
index.scala.html
@(title: String,templateName:String)
@if(templateName == "foo"){
@templates.foo(title,templateName){
}
}
else if(templateName == "bar"){
@templates.bar(title,templateName){
} else {
......
}
私は自分の問題を適切に説明していないと思います:
@johanandrenまあ、誤解があるようです。はい、コントローラーからテンプレート名を動的に指定 することは許可されていないことを理解してい(if reflection isn't used, and it seems to have its own cons as well,thanks to you and @Khanser)
ます。これはまったく計画していませんでした。
しかし、「個々のサブテンプレートの周りに共通のテンプレートを適用したいだけなら」とあなたが言ったように、私の主な懸念は、あなたが述べたように、ユーザー=>異なるメインテンプレートに基づいて、一般的なテンプレートを持たないことです。はい、目的に合わせてスイッチ/ケースを使用できますが、 * テンプレート名を知って、すべてのサブテンプレートにハードコードする必要があります。
はい、「templates->main.scala.html」および「sub-templates=>index.scala.html」などの使用と、メイン テンプレートにサブテンプレートを注入することを理解しました。そして、私はすでにこれを行っていると思います。invert the template flow