Building Reusable Components
As your site grows, the same card or button layout appears everywhere. In Clean Language, a component is just a function that returns a string of HTML. No framework magic, no virtual DOM — just functions you can call anywhere.
Part of: Frame framework
Any function with an html: block is a component:
functions:
string product_card(string name, string price, string url)
html:
<div class="product-card">
<h3 class="product-name">{name}</h3>
<p class="product-price">{price}</p>
<a href="{url}" class="btn">View Details</a>
</div>The function takes data as parameters and returns an HTML string. The name, price, and url variables are interpolated and HTML-escaped automatically — user-supplied data cannot inject HTML into your page.
Call the component in your endpoint and combine the results:
endpoints server:
GET "/products" :
string card1 = product_card("Clean Language Book", "$29", "/books/1")
string card2 = product_card("Starter Course", "Free", "/courses/starter")
html:
<!DOCTYPE html><html><body>
<section class="products-grid">
{!card1}
{!card2}
</section>
</body></html>GET /products → HTML page with two product cardsUse the raw interpolation form (curly-brace with exclamation) to insert HTML from a trusted component. Without it, the HTML tags would be escaped and appear as literal text. The rule: plain curly braces for user data, curly-brace-! for component output.
- A component is a function that returns a string using an html: block
- Plain curly-brace interpolation auto-escapes — use for user-supplied text
- Curly-brace-! interpolation inserts raw HTML — use for component output you control
- Put components in a helpers.cln file and import it in your server