Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Twitter Bootstrap 3 with play framework 2.3

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?

like image 278
Ram's stack Avatar asked Nov 23 '14 16:11

Ram's stack


People also ask

What is twitter bootstrap and why would a developer use 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.

What does twitter bootstrap do?

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.


4 Answers

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

like image 61
biesior Avatar answered Oct 14 '22 06:10

biesior


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>
  • WebJars documentation
like image 39
smac89 Avatar answered Oct 14 '22 07:10

smac89


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"
)
like image 21
karim elhelawy Avatar answered Oct 14 '22 05:10

karim elhelawy


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>
like image 29
ecamur Avatar answered Oct 14 '22 06:10

ecamur