Pergunta

I'm working my way through Lisp For The Web by Adam Tornhill and I'm stuck at generating a html page with an li element in it.

(with-html-output (*standard-output* nil :prologue t :indent t)
   (htm
       (:li (:a :href "Link" "Vote!")
        )))

When I compile it the following output is printed to the REPL

(with-html-output (*standard-output* nil :prologue t :indent t)
   (htm 
       (:li (:a :href "Link" "Vote!")
        )))
 <!DOCTYPE html>

<li>
  <a href='Link'>Vote!
  </a>
</li>
"
<li>
  <a href='Link'>Vote!
  </a>     
</li>"   

The string at the end of the output usually is not added and a site including this does not render in hunchentoot. Adding :ol around :li does not help and I wanted to keep the example minimal.

The code from the book as reference:

(define-easy-handler (retro-games :uri "/retro-games") () 
  (standard-page (:title "Top Retro Games") 
   (:h1 "Vote on your all time favourite retro games!") 
   (:p "Missing a game? Make it available for votes " (:a :href "new-game" "here")) 
   (:h2 "Current stand") 
   (:div :id "chart" ; Used for CSS styling of the links. 
     (:ol 
 (dolist (game (games)) 
  (htm   
   (:li (:a :href (format nil "vote?name=~a" (escape-string ; avoid injection attacks 
                                                 (name game))) "Vote!") 
         (fmt "~A with ~d votes" (name game) (votes game)))))))))
Foi útil?

Solução

What you see first is what the form prints to *standard-output* when evaluated. The string seen after that is the form's result, printed by the REPL. As your Hunchentoot handler is only interested in what goes to the output stream, the result does not matter.

To simply get the result as string, you can use with-html-output-to-string:

(with-html-output-to-string (str nil :prologue t :indent t)
  (htm 
   (:li (:a :href "Link" "Vote!"))))

On the other hand, to suppress the result string and only see the document as written out, you can do something like this:

(progn
  (with-html-output (*standard-output* nil :prologue t :indent t)
    (htm 
     (:li (:a :href "Link" "Vote!"))))
  (values))
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top