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:
- Isn't this error message misleading? It should have been something like
template not found: template.tpl - 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
Apprecord:_myapp :: Snaplet Myapp - In
appinitializer function, I added:n <- embedSnaplet "myapp" myapp myappInitand 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.
1.: I agree that there should be two different types of errors for rendering templates. Sadly as far as I know that isn't the case.
2.: Short answer: The directory used is written in your heistInit function. e.g.
means that all the files in "snaplets/heist/templates/" can be accessed, including sub directories.
Long answer:
The default behaviour of the heist directory stucture works as follows: All .tpl files are accessible from the snaplet/heist/templates/ directory. Meaning
will access the file
Which can be accessed at the url
You can also use sub directories, e.g.:
To modify this behaviour you can adjust the heistInit function.
Let's say you want the directory path to be "snaplets/heist/" instead of "snaplets/heist/templates/"
simply change:
to this:
The argument of heistInit is the directory location of your tpl files. So you could adjust that however you wish.
I hope this answers your question.