[cl-who-devel] Question about splitting tags in a dolist...

Jim Barrows jim.barrows at gmail.com
Fri Nov 18 18:13:41 UTC 2011


I figured it out, thanks to Jeffrey.  I appreciated the help, you pointed
me in the right direction.
What's really cool, is that by forcing me to not split the tags, I ended up
with a much cleaner solution.  It'll be even cleaner when I fix the hard
coded list building :)

(defun people-and-organizations-list ()
"Creates a list of people and organizations"
(web-common::with-html
(:section :id "people-and-organization-list"
(:a :href *add-organization-url* "Add Organization")
(let ((result-list (people-and-organizations-query))
(columns 3))
(loop for i from 0 to (list-length result-list) by 3 do
 (people-and-organizations-row (list (nth i result-list)
 (nth (+ 1 i) result-list)
 (nth (+ 2 i) result-list))))))))


On Thu, Nov 17, 2011 at 10:19 AM, Jeffrey Cunningham <
jeffrey at jkcunningham.com> wrote:

> **
> On Thu, 17 Nov 2011 07:47:32 -0800, Jim Barrows <jim.barrows at gmail.com>
> wrote:
>
> I'm pulling records from a database, and I don't know how many I'll have.
>  I need to display them in a 3 by X grid built in CSS.  So it needs to look
> something like:
> (:div :class "row"
>   (:div :class "span-one-third" "1/3")
>   (:div :class "span-one-third" "1/3")
>   (:div :class "span-one-third" "1/3"))
>
> Since I don't know how many rows are returning, I can't really hard code
> it like the above example.
>
> I'm new to lisp, so I may just be thinking about this in the wrong way.
>  In Java, opening a tag like this and closing it is a very common pattern.
>  Maybe I'm just thinking too much in Java...
> --
> James A Barrows
>
>
> Here's one way:
>
> (let ((records '((1 2 3) (4 5 6) (7 8 9))))
>    (with-html-output (*standard-output* nil :indent 0)
>      (dolist (rec records)
>        (htm (:div :class "row"
>          (dolist (col rec)
>            (htm (:div :class "span-one-third" (str col)))))))))
>
> Jeff Cunningham
>
>
>
>
>


-- 
James A Barrows
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/cl-who-devel/attachments/20111118/282d4a2d/attachment.html>


More information about the Cl-who-devel mailing list