Question

I'm trying to convert a Play! 2.0 application into a Scalatra application. I've had some success, but there are 3 issues remaining, 1 of which has its own ticket.

1) I understand that src/main/webapp/WEB-INF/views and src/main/webapp/WEB-INF/layouts contain the layouts in a standard directory structure. I was not able to get this to work in a different heirarchy, though, e.g. if I have 2 servlets and wanted different views for them:

- WEB-INF
 - servlet1
   - views
   - layouts
 - servlet2
   - views
   - layouts

In the example I provided, I can't adequately reference anything not directly under WEB-INF/views or WEB-INF/layouts. Presumably, it's because I'm not declaring something in web.xml correctly?

// works
get("/") {
  contentType = "text/html"
  templateEngine.layout("/WEB-INF/views/app.jade")
}

// no worky
get("/") {
  contentType = "text/html"
  templateEngine.layout("/WEB-INF/servlet1/views/app.jade") // where servlet1/layouts/default.jade exists
}

2) What's up with templating? For this conversion to work, I need to be able to use Underscore templates in conjunction with whatever is available to me from Scalatra (Jade, Mustache, etc). I chose Jade because all the default examples use it.

I'm really running into two sub-issues here.

1) I can't seem to use Underscore templates with Jade, even though I have included the javascripts in this ticket. Maybe this works, maybe it doesn't. This is probably because....

2) My include statements look like tags instead of actually including the partial, so it's really hard to test the first sub-issue.

<!-- / Nav -->
<include>nav</include>
<!-- / Action1 -->
<include>action1</include>
<include>action2</include>
<!-- / Wireframe -->
<div id="default-region">
  <script id="template-layout" type="text/template">
    <div id="region-nav"></div>
    <div id="region-content"></div>
  </script>
</div>
<!-- / CSS and JavaScripts relative to Backbone app -->
<include>assets</include>

What the equivalent app.jade file looks like:

// Nav
include nav

// Action1
include action1
include action2

// Wireframe
div#default-region
  script#template-layout(type="text/template")
    div#region-nav
    div#region-content

// CSS and JavaScripts relative to Backbone app
include assets

Any help would be appreciated!

Was it helpful?

Solution

You can structure your views differently or you have to provide a different filesystem configuration for your views. You can configure that by overriding getRenderContext.

You don't need to call templateEngine.layout, but instead use our helper methods. For jade with a layout that becomes jade("my_view", "layout" -> "/WEB-INF/layouts/authenticated.jade")

As for including those tags, etc. perhaps you mean this?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top