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?
Twitter Bootstrap was originally named as Twitter Blueprint before it was released as an open-source project on GitHub on August 19th, 2011. Bootstrap was created as an internal tool with the aim of eliminating inconsistencies among developers using different tools.
Twitter Bootstrap is a front end framework to develop web apps and sites fast. In modern web development, there are several components which are required in almost all web projects. Bootstrap provides you with all those basic modules - Grid, Typography, Tables, Forms, Buttons, and Responsiveness.
DO NOT divide downloaded library manually, what for? It contains relative paths.
Just unzip it i.e. into public/bootstrap
folder and include JS/CSS from there as common public asset:
<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:
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
My solution was as follows:
In 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)
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
In your file.scala.html
file, you include bootstrap like so:
<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>
In the build.sbt
file add the following:
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"
)
in Play 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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With