1

嗨,我正在尝试在 playframework 2 中使用 mustache 模板。所以我的 index.scala.html 看起来像

@import com.feth.play.module.pa.views.html._

<!doctype html>
<!--[if lt IE 7 ]> <html lang="en" class="no-js ie6"> <![endif]-->
<!--[if IE 7 ]>    <html lang="en" class="no-js ie7"> <![endif]-->
<!--[if IE 8 ]>    <html lang="en" class="no-js ie8"> <![endif]-->
<!--[if IE 9 ]>    <html lang="en" class="no-js ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]-->
<head>


<title>Test</title>

<script data-main="@routes.Assets.at("javascripts/main.js")" src="@routes.Assets.at("javascripts/require.js")"></script>


<body>
<header> 
</header>
</body>
</html>

我通过主干视图插入标题。

define(['use!jquery', 'use!underscore', 'use!backbone', 'text!templates/View.HeaderView.html',
    'bootstrap', 'bootstrap-dropdown'],
    function($, _, Backbone,headerViewTemplate) {


    return Backbone.View.extend({

        el: $('header'),

        events: {

        },

        initialize: function(options) {
            console.log('headerview init');
            this.template = headerViewTemplate;
        }
}

View.HeaderView.Html 定义如下

 <div id="auth-status">
                            @currentAuth() { auth =>
                            @if(auth != null) {
                            <div class="btn-group pull-right" id="auth-loggedin" style="display:auto">
                                <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
                                    <i class="icon-user" id="auth-displayname"></i> Welcome
                                    <span class="caret"></span>
                                </a>
                                <ul class="dropdown-menu">

                                    <li><a href="#">Settings</a></li>
                                    <li class="divider"></li>
                                    <li><a href="@com.feth.play.module.pa.controllers.routes.Authenticate.logout" id="auth-logoutlink">Sign Out</a></li>
                                </ul>
                            </div>
                            }
                            @if(auth == null) {
                            @forProviders() { p =>
                            <div class="btn pull-right" id="auth-loggedout">
                                <a href="@p.getUrl()" id="auth-loginlink">
                                    <i class="icon-user"></i> Login With Facebook</a>
                            </div>
                            }


                            }
                            }
</div>

所以我遇到的问题是 scala 模板显示为常规文本而不是 scala 代码。如果我将代码放在 index.scala.html 中,它就可以工作。

帮助!!!

4

1 回答 1

1

您的View.HeaderView.Html文件未被检测为 scala 代码,也未被执行/编译。

  • 首先,将它放在views应用程序的包中。
  • 其次使用.scala.html扩展。否则编译器将找不到它。
于 2012-10-18T07:48:35.740 回答