twitter-bootstrap 如何在播放框架 2.3 中使用 Twitter Bootstrap 3
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27091595/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use Twitter Bootstrap 3 with play framework 2.3
提问by Ram's stack
I have been trying adding bootstrap's js and css files to public/javascripts and public/stylesheets application in play framework application. I donno why but I get a blank output. Is it the correct way to proceed for bootstrap v3 with play v2.3? If not what's the correct procedure to do it?
我一直在尝试将 bootstrap 的 js 和 css 文件添加到 play 框架应用程序中的 public/javascripts 和 public/stylesheets 应用程序。我不知道为什么,但我得到一个空白的输出。这是使用 play v2.3 进行引导程序 v3 的正确方法吗?如果不是,那么正确的程序是什么?
回答by biesior
DO NOTdivide downloaded library manually, what for? It contains relative paths.
不要手动分割下载的库,有什么用?它包含相对路径。
Just unzip it i.e. into public/bootstrapfolder and include JS/CSS from there as common public asset:
只需将它解压缩到public/bootstrap文件夹中,并从那里包含 JS/CSS 作为公共公共资产:
<link rel="stylesheet"
href="@routes.Assets.at("assets/bootstrap/css/bootstrap.css")">
<script type='text/javascript'
src='@routes.Assets.at("assets/bootstrap/js/bootstrap.js")'></script>
of course I assume that you have default route created by Play:
当然,我假设您有 Play 创建的默认路由:
GET /assets/*file controllers.Assets.at(path="/public", file)
TIP: these folders you mentioned are just sample, it doesn't oblique you to anything... you can move/rename/delete them, whatever
提示:您提到的这些文件夹只是示例,它不会使您倾斜任何东西...您可以移动/重命名/删除它们,无论如何
回答by karim elhelawy
In the build.sbtfile add the following:
在build.sbt文件中添加以下内容:
resolvers ++= Seq(
"webjars" at "http://webjars.github.com/m2"
)
libraryDependencies ++= Seq(
"org.webjars" %% "webjars-play" % "2.3.0",
"org.webjars" % "bootstrap" % "3.0.0" exclude("org.webjars", "jquery"),
"org.webjars" % "jquery" % "1.8.3"
)
回答by ecamur
in Play 2.5.x
在播放 2.5.x
<link rel="stylesheet" href="@routes.Assets.versioned("bootstrap/css/bootstrap.css")">
<script type='text/javascript' src='@routes.Assets.versioned("bootstrap/js/bootstrap.js")'></script>
回答by smac89
My solution was as follows:
我的解决方案如下:
In build.sbt:
在 build.sbt 中:
libraryDependencies ++= Seq(
"org.webjars" % "bootstrap" % "3.3.7"
)
In conf/routes, ensure you have the following line: (This should be included by default unless you deleted it)
在 中conf/routes,确保您有以下行:(默认情况下应包括在内,除非您将其删除)
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
In your file.scala.htmlfile, you include bootstrap like so:
在您的file.scala.html文件中,您像这样包含引导程序:
<link rel="stylesheet" media="screen" href="@routes.Assets.versioned("lib/bootstrap/css/bootstrap.min.css")">
<script src="@routes.Assets.versioned("lib/bootstrap/js/bootstrap.min.js")" crossorigin="anonymous"></script>
回答by rjmAmaro
In the new Play 2.4 version, you should use:
在新的 Play 2.4 版本中,您应该使用:
@routes.Assets.versioned("an_asset")
instead of:
代替:
@routes.Assets.at("an_asset")
But remember to keep this in the routesfile:
但请记住将其保存在路由文件中:
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)

