Question

I'm not sure whether this is an issue with my use of cl-who (specifically with-html-output-to-string and with-html-output) or an issue with my understanding of Common Lisp (as this is my first project using Lisp).

I created a function to create form fields:

(defun form-field (type name label)
  (cl-who:with-html-output (*standard-output* nil)
    (:div :class "field"
      (:label :for name label)
      (:input :type type :name name))))

When using this function, ie: (form-field "text" "username" "Username") the parameter label seems to be ignored... the HTML output is:

<div class="field"><label for="username"></label>
<input type="text" name="username"/></div>

instead of the expected output:

<div class="field"><label for="username">Username</label>
<input type="text" name="username"/></div>

If I modify the function and add a print statement:

(defun form-field (type name label)
  (cl-who:with-html-output (*standard-output* nil)
    (print label)
    (:div :class "field"
      (:label :for name label)
      (:input :type type :name name))))

The "Username" string is successfully output (but still ignored in the HTML)... any ideas what might cause this?

Keep in mind, I'm calling this function within a cl-who:with-html-output-to-string for use with hunchentoot.

Was it helpful?

Solution

This situation is described in the CL-WHO evaluation rules under "A form which is neither a string nor a keyword..." (:label :for name label) falls under that rule, and it's just evaluated, but it doesn't output anything so it has no effect. One easy fix: use (str label) instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top