1

I've tried to render a page index.ssp in my scalatra controller, but it shows me an error:

ssp("index")
//Error : Template file extension missing. Cannot determine which template processor to use.

My Servlet extends ScalatraServlet with ScalateSupport and my file is in WEB-INF directory. i've left the extension because the document stated .ssp is implicit and not required.

Is there anything else i need to do other than this?directory.

Dineshkumar
  • 4,165
  • 5
  • 29
  • 43
  • The templates are usually in WEB-INF/templates/(views|layouts). You can also take a look at the source how the templates are looked up: https://github.com/scalatra/scalatra/blob/2.4.x/scalate/src/main/scala/org/scalatra/scalate/ScalateSupport.scala#L175-L191 – Stefan Ollinger Feb 12 '15 at 23:07
  • I've also tried it with the file in views folder and still didn't work – Dineshkumar Feb 13 '15 at 04:47

2 Answers2

2

When rendering your views Scalate will look for a layout in the following folder: /WEB-INF/layouts/default.ssp (or default.scaml but lets consider ssp). So, create this file and add the following: (this snippet is taken from the book Scalatra in Action)

<%@ val body:String %>
<html>
  <head>
    <title>Scalatra CMS</title>

    <!-- Bootstrap -->
    <link href="/css/bootstrap.min.css" rel="stylesheet" media="screen">

    <style type="text/css">
      body {
      padding-top: 60px;
      }
    </style>
  </head>
  <body>
    <div class="navbar navbar-inverse navbar-fixed-top">
      <div class="navbar-inner">
        <div class="container">
          <a class="btn btn-navbar" data-toggle="collapse"
              data-target=".nav-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </a>
          <ul class="nav">
            <li>
              <a class="brand" href="/" id="server">
                Scalatra CMS
              </a>
            </li>
          </ul>
        </div>
      </div>
    </div>
    <div class="container">
    <%= unescape(body) %>
    </div> <!-- /container -->
  </body>
</html>

Then add an page, say bla.ssp to /WEB-INF/templates/views/pages. The bla.ssp will contain your html content, e.g.:

<div class="row">
    <h2>everyone </h2>
    <p class="lead">hello </p>
</div>

In the servlet add the following:

layoutTemplate("/WEB-INF/templates/views/pages/bla.ssp")

This should work.

Dan Barowy
  • 2,270
  • 24
  • 35
kostas
  • 1,959
  • 1
  • 24
  • 43
0

With scalatra 2.5.1 i was given a different default folder structure:

webapp\WEB-INF\templates\layout\default.jade
webapp\WEB-INF\templates\views

were i added:

webapp\WEB-INF\templates\views\index.ssp

, then in the controller i have:

contentType="text/html"
jade("/templates/views/index.ssp", "layout" -> "WEB-INF/templates/layouts/default.jade",
  "title" -> <title>,
   ... -> ...)
Joel Mata
  • 456
  • 4
  • 8