I have many routes in my app that get information from a database. In one particular situation, I am getting HTML content from a database to render it with cl-who
.
I am not sure why the content from the DB will not render. The rest of the page works fine.
When I test adding html into the route manually (hard coded html tags) it works fine. In the case when I use the (second (get-content))
(see below) the html from the DB is not added to the template.
What am I missing?
Database macro
(defmacro access-db(db &body query)
`(progn
(clsql:connect ,db)
(unwind-protect (progn ,@query)
(disconnect-db ,db))))
Page Macro
(defmacro defpage ((&key title) &body content)
`(cl-who:with-html-output-to-string
(*standard-output* nil :prologue t :indent t)
(:html
:xmlns "http://www.w3.org/1999/xhtml"
:xml\:lang "en"
:lang "en"
(:head
(:meta
:http-equiv "Content-Type"
:content "text/html;charset=utf-8")
(:title
,(format nil "~A" title))
(:link :type "text/css"
:rel "stylesheet"
:href "/styles.css"))
(:body :class "whole-page"
(:div :class "site-articles"
(:div :class "article-body"
(:div :class "on-page-title"
(:h1 :class "main-header" ,title))
,@content))))))
Hunchentoot route
(define-easy-handler (test-page :uri "/wow") ()
(let ((content
(bt:make-thread
(lambda ()
(second (get-content))))))
(defpage (:title "Main One")
(bt:join-thread content))))
get-content uses access-db
function and returns a list the first item from the database. A title and HTML. The html is second in that list.
Get content
(defun get-content ()
(let ((blogs
(access-db *PSQL-CONNECT-INFO*
(clsql:query
"select * from content"))))
(first blogs)))