How to use Twitter Bootstrap 2 with play framework 2.x

前端 未结 8 1407
感动是毒
感动是毒 2020-12-04 08:11

I know that current Play! distribution has a helper for Bootstrap 1.4. What should I do if I want to use the current version of Bootstrap?

8条回答
  •  独厮守ぢ
    2020-12-04 08:51

    A quick and maintainable approach is to use WebJars (a client-side dependency manager by Typesafe Dev Advocate: James Ward), with a few lines in your Build.scala, you can easily add Bootstrap (e.g. version 2.3, 3.0, etc) - and much more - to your project.

    1) Here's the documentation example for adding Bootstrap 2.3 to Play 2.1, in your Build.scala:

    import sbt._
    import Keys._
    import play.Project
    
    object ApplicationBuild extends Build {
      val appName         = "foo"
      val appVersion      = "1.0-SNAPSHOT"
    
      val appDependencies = Seq(
        "org.webjars" %% "webjars-play" % "2.1.0-2",
        "org.webjars" % "bootstrap" % "2.3.2"
      )
    
      val main = Project(appName, appVersion, appDependencies).settings()
    }
    

    2) Then add an entry to your routes file:

    GET     /webjars/*file                    controllers.WebJarAssets.at(file)
    

    3) Add the relevant links to your templates:

    
    
    

    Note that WebJars will actually try and find your resources for you, you don't need to full qualify the asset locations.

提交回复
热议问题