0

I have (finally) set up a sub-project in the Play Framework but cannot access the stylesheet (for the sub-project). I have the following:

Project Structure

   main-project
   _build.sbt
   _app
     _controllers
     _models
     _views
   _conf
     _application.conf
     _routes
   _modules
     _admin
       _build.sbt
       _app
         _controllers
            _admin
               _Assets
               _HomeController
         _models
         _views
            _admin
               _aMain.scala.html
       _assets
         _less
            _admin.less
       _conf
         _admin.routes
   _project
     _build.properties
     _plugins.sbt

admin.routes

   GET /                  controllers.admin.HomeController.index

   GET /assets/*file      controllers.admin.Assets.at(path="/public/lib/admin", file)

aMain.scala.html

@(title: String)

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>@title</title>
        <link rel="stylesheet" media="screen" href="@admin.routes.Assets.at("less/admin.less")">
        <link rel="shortcut icon" type="image/png" href="@admin.routes.Assets.at("images/favicon.png")">
        <script src="@admin.routes.Assets.at("javascripts/hello.js")" type="text/javascript"></script>
    </head>
    <body>
        @* And here's where we render the `Html` object containing
         * the page content. *@


        <div class="blue-italic">@title</div>

    </body>
</html>

So the page loads successfully but not the stylesheet. I even made the paths and the filenames unique to avoid any potential conflicts. Can anyone see what is going wrong here? Thanks

1 Answers1

0

You should try this (just use the unique Assets controller):

GET /assets/*file controllers.Assets.at(path="/public/lib/admin", file)

From the scala play documentation:

Note: Resources are served from a unique classloader, and thus resource path must be relative from project classpath root. Subprojects resources are generated in target/web/public/main/lib/{module-name}, so the resources are accessible from /public/lib/{module-name} when using play.api.Application#resources(uri) method, which is what the Assets.at method does.

Romain Lebran
  • 38
  • 1
  • 2
  • 8
  • Thanks. Firstly I had to have the `admin.routes` file routing to `controllers.admin.Assets.at(path="/public/lib/admin", file)` to create the `target/web/public/main/lib/` directory (in the admin sub-project) upon compilation. But I did have an issue with the structure - it appears that `modules/admin/assets/less/admin.less` needs to be inside of the `app` folder, i.e. `modules/admin/app/assets/less/admin.less`. So I have since been able to successfully load in a `css` file. – jesus g_force Harris Oct 31 '17 at 19:18
  • However as you will see from my files; I was hoping to load a `.less` file to create more dynamic styling so this now appears to be the issue for me. I have therefore [created a new question](https://stackoverflow.com/questions/47042882/cannot-load-sbt-less-stylesheets-into-a-subproject-in-the-play-framework) as it has changed its' nature completely. Thanks for the efforts! – jesus g_force Harris Oct 31 '17 at 19:20