Snap-Heist: why my template is not rendered?

Viewed 345

I'm trying to render a template using Snap and Heist.

I'm sure my handler function is called correctly (if I replace handler function's content with undefined, it fails as expected. Debug.Trace.trace also works as expected).

This handler function consists of one line: render "template". But for some reason I'm getting No handler accepted <url> error instead of a template not found or something like that.

I think the problem here is that I'm placing my template in wrong directory, but there's no way to know where are searched for templates. So my question is:

  1. Isn't this error message misleading? It should have been something like template not found: template.tpl
  2. Where can I know which directories are searched for templates?

I think the snap application created by snap init is the problem. I only made slight modifications on it:

  • I added one more field to App record: _myapp :: Snaplet Myapp
  • In app initializer function, I added: n <- embedSnaplet "myapp" myapp myappInit and then passed n to record.
  • I created new file src/Myapp.hs.

Here are relevant parts in Myapp.hs:

myappInit = do
    ...
    h <- nestSnaplet "" heist $ hesitInit "myapp_templates"
    addRoutes routes
    ...

routes = [ ("/submit", submitHandler) ]

submitHandler = trace "rendering submit" $ render "submit"

But for some reason even though I see rendering submit printed to console when I go to http://0.0.0.0:8000/myapp/submit, I get No handler accepted "/hsnews/submit" message as HTTP response (instead of rendered template). I have submit.tpl and _submit.tpl in snaplets/heist/myapp_templates.

2 Answers
Related