Backbone.js 在Playframework 2中使用胡须模板

Backbone.js 在Playframework 2中使用胡须模板,backbone.js,playframework,playframework-2.0,Backbone.js,Playframework,Playframework 2.0,嗨,我正在尝试在playframework 2中使用胡须模板。所以我的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="e

嗨,我正在尝试在playframework 2中使用胡须模板。所以我的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>
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>

@currentAuth(){auth=>
@如果(auth!=null){
} @if(auth==null){ @forProviders(){p=> } } }
所以我遇到的问题是scala模板显示为常规文本,而不是scala代码。如果我将代码放在index.scala.html中,它就会工作


救命啊

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

  • 首先,将其放入应用程序的
    视图
    包中
  • 其次,使用
    .scala.html
    扩展名。否则编译器将找不到它
您的
视图.HeaderView.Html
文件未检测为scala代码,并且未执行/编译

  • 首先,将其放入应用程序的
    视图
    包中
  • 其次,使用
    .scala.html
    扩展名。否则编译器将找不到它
我理解这一点,但headerview(backboneview)如何访问此scala模板?我需要将依赖项包含到模板中。如果我在app/view文件夹中将其声明为scala模板,我该怎么做呢。javascripts在public/javascript文件夹中。更不用说我在stackoverflow()上看到了另一个讨论这个问题的线程。因此,基本上您无法使用javascript访问scala模板(服务器端)。为了解决我的问题,我创建了headerView作为scala模板,并包含在我的主scala模板中。在客户端渲染之后,可以在客户端使用适当的div进行操作。谢谢你,这是你必须做的。创建一个scala模板并将主scala模板导入为。你的意思是导入scala模板,然后实例化它吗?例如@headerview(),它不需要在脚本标记中。事实上,标记中的主干视图被弄乱了。我理解,但headerview(backboneview)如何访问此scala模板?我需要将依赖项包含到模板中。如果我在app/view文件夹中将其声明为scala模板,我该怎么做呢。javascripts在public/javascript文件夹中。更不用说我在stackoverflow()上看到了另一个讨论这个问题的线程。因此,基本上您无法使用javascript访问scala模板(服务器端)。为了解决我的问题,我创建了headerView作为scala模板,并包含在我的主scala模板中。在客户端渲染之后,可以在客户端使用适当的div进行操作。谢谢你,这是你必须做的。创建一个scala模板,然后将主scala模板作为导入。你是说导入scala模板,然后实例化它吗?例如@headerview(),它不需要在脚本标记中。事实上,它会弄乱标记中的主干视图。
 <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>