#+title: Using cl-sbt/accordion Macros in a Web Application #+author: Marcus Kammer #+email: marcus.kammer@mailbox.org #+date: [2023-09-02 Sat] * Introduction The accordion component is a popular UI element that helps to organize and present content in a space-efficient manner. Accordions consist of a list of headers that users can click on to toggle the visibility of associated content. This is particularly useful for presenting large amounts of information in a confined space while keeping the interface clean and uncluttered. The Accordion component is perfect for FAQ sections, multi-part forms, or any situation where you need to present the user with a range of options or information, but you want to keep the interface uncluttered by hiding content that isn't immediately necessary. ** Bootstrap Accordions [[https://getbootstrap.com/docs/][Bootstrap]] is a popular front-end framework that provides ready-to-use components for building responsive and modern web applications. One of its components is the [[https://getbootstrap.com/docs/5.3/components/accordion/][accordion]], which enhances the user experience by providing a user-friendly way to display and interact with content. *** How Bootstrap Accordions Work Bootstrap accordions are created using HTML, CSS, and JavaScript. The Bootstrap JavaScript library adds the necessary interactivity to the accordion. Here's how it works: - Each accordion item consists of a header and content section. - Clicking on an accordion item's header toggles the visibility of its content. - By default, only one item's content is visible at a time. Clicking on a header closes any open content before opening the clicked item's content. - Bootstrap's JavaScript library manages the animations and transitions for smooth content expansion and collapse. * Integrating cl-sbt/accordion Macros To create Bootstrap-style accordions in your Common Lisp web application, you can use the cl-sbt/accordion macros. These macros provide a convenient way to generate the necessary HTML structure for accordion components. Here's how you can integrate them into your project: #+begin_src lisp (defpackage my-web-app (:use :cl :cl-sbt/accordion) (:export :generate-accordion-page)) (in-package :my-web-app) (defun generate-accordion-page () "Generates an HTML page with an accordion using cl-sbt/accordion macros." (spinneret:with-html-string (:html (:head (:title "Accordion Example") ;; Include Bootstrap CSS and JavaScript links here ) (:body (:h1 "Accordion Example") (accordion "myAccordion" (:target "collapseOne" :name "Section 1" :show t :content "Content for section 1.") (:target "collapseTwo" :name "Section 2" :content "Content for section 2.") (:target "collapseThree" :name "Section 3" :content "Content for section 3.")) ;; Include Bootstrap JavaScript initialization script here )))) (generate-accordion-page) #+end_src #+RESULTS: #+begin_example Accordion Example

Accordion Example

Content for section 1.

Content for section 2.

Content for section 3.
#+end_example This example demonstrates how to integrate the cl-sbt/accordion macros into a web application to create an interactive accordion component. The macros help generate the necessary HTML structure for the accordion, which allows users to navigate through content conveniently.