我有一個名爲mainBody
與表單模板:播放框架模板沒有HTML類型
@(title: String)(html: Html, moreScripts: Html = Html(""))
我能夠把這個像
views.html.mainBody("All properties")(views.html.showProperties(list))
views.html.showProperties()
是另一個模板。我的印象是模板只是返回Html
的函數。但是,如果我延長這:
views.html.mainBody("All properties")(views.html.showProperties(list), views.html.showPropertiesScripts)
哪裏views.html.showPropertiesScripts
只是一些HTML代碼模板,我得到的錯誤:
play.PlayExceptions$CompilationException: Compilation error[type mismatch;
found : views.html.showPropertiesScripts.type
required: play.twirl.api.Html]
at play.PlayExceptions$CompilationException$.apply(PlayExceptions.scala:27) ~[na:na]
at play.PlayExceptions$CompilationException$.apply(PlayExceptions.scala:27) ~[na:na]
at scala.Option.map(Option.scala:145) ~[scala-library-2.11.2.jar:na]
at play.PlayReloader$$anon$1$$anonfun$play$PlayReloader$$anon$$taskFailureHandler$1.apply(PlayReloader.scala:234) ~[na:na]
at play.PlayReloader$$anon$1$$anonfun$play$PlayReloader$$anon$$taskFailureHandler$1.apply(PlayReloader.scala:229) ~[na:na]
我不明白這一點。而不是預期的類型Html
,views.html.showPropertiesScripts
是views.html.showPropertiesScripts.type
?這是什麼,爲什麼views.html.showPropertiesScripts
不是Html
(就像我的其他模板)?
這個工程,我喜歡比我的風格更好。但是,請你解釋爲什麼這個工作原理和我的原始代碼不是? – Mike 2014-10-09 23:35:11
Mike TBH我從未分析過Play的模板引擎,如果您感興趣,請下載源代碼;)一般規則是在第一個括號中聲明視圖的所有參數(強制性和可選),並在第二個帶有內容的「Html」中聲明。 – biesior 2014-10-10 08:02:51
好得多。作品。 – 2016-11-08 17:28:25