Next: SXML Templating, Previous: Templating APIs, Up: Layouts and Rendering in GNU Artanis [Contents]
Example: Write a tpl file named "my.tpl":
<html> <p> <%= "This is tpl test!" %> </p> <p> <% (format #t "And this is ~a" (getcwd)) %> </p> <p> <%= external-var %> </p> </html>
Of course, the ext filename ".tpl" is trivial, you may name it whatever you like.
(get "/test" (lambda (rc) (let ((external-var 123)) (tpl->response "my.tpl" (the-environment))))) (run #:port 8080)
In this case, make sure to put my.tpl to the same path with your GNU Artanis code.
Because external-var is defined outside the file "my.tpl", and it’s bound in let with 123, you have to pass (the-environment). Or the template render will blame that it can’t find variable named external-var.
If you don’t have any external var needs to be referenced, just use (tpl->response "file.tpl") is fine.
Then see http://localhost:3000/test in your browser.