Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter Bootstrap in Play applications

I'm going to involve Twitter Bootstrap in my Play project. I found some articles about it but, as I understood, there is no a standard approach.

So what's the most standard way of working with Twitter Bootstrap in Play applications?

like image 782
Incerteza Avatar asked Dec 20 '25 09:12

Incerteza


1 Answers

You can use webjars for that. First you have to add bootstrap to dependencies eg. in project/dependencies.scala:

import sbt._
object Dependencies {
  val bootstrapVersion = "(2.3.2,)"
...
  val bootstrap = "org.webjars" % "bootstrap" % bootstrapVersion
...
  val myDependencies = Seq(..., bootstrap, ...)
}

The value of the bootstrapVersion tells sbt to update to the latest bleeding-edge bootstrap. You can also fix it to a specific version you desire. Then use it in the main build.sbt:

import Dependencies._

...

libraryDependencies ++= Seq(cache) ++ myDependencies

play.Project.playScalaSettings

...

Then in the main layout file (like app/views/main.scala.html)

<script type='text/javascript' src='@routes.WebJarAssets.at(WebJarAssets.locate("bootstrap.min.js"))'></script>

<link rel="stylesheet" media="screen" href="@routes.WebJarAssets.at(WebJarAssets.locate("bootstrap.min.css"))">

Then in the app/assets/stylesheets you can put only modifications of the bootstrap styles.

The advantage of the above is that you set the bootstrap (or any other webjar) version in exactly one place.

See also this question.

like image 137
Rajish Avatar answered Dec 23 '25 01:12

Rajish



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!