HypertextTemplates.jl

HTML templating system for Julia

HypertextTemplates.jl is a powerful and efficient HTML templating system that lets you write HTML using Julia's macro syntax. It provides zero-allocation rendering, a sophisticated component system, and seamless integration with Julia's ecosystem.

Key Features

  • Natural Syntax - Write HTML using Julia macros that feel like native code
  • Zero-allocation rendering - Direct IO streaming without intermediate DOM construction
  • Component System - Build reusable components with props and slots
  • Context System - Pass data through component trees without prop drilling
  • Automatic HTML escaping - Automatic XSS protection with context-aware escaping
  • Development tools - Source location tracking and editor integration
  • Streaming rendering - Asynchronous rendering with micro-batched output
  • Markdown Support - Create components from Markdown files

Quick Start

using HypertextTemplates
using HypertextTemplates.Elements

# Simple example
html = @render @div {class = "container"} begin
    @h1 "Welcome to HypertextTemplates!"
    @p "Build fast, secure web applications with Julia."
end

<div class="container">
  <h1>Welcome to HypertextTemplates!</h1>
  <p>Build fast, secure web applications with Julia.</p>
</div>

# Component example
@component function article_card(; title, author, content)
    @article {class = "card"} begin
        @header begin
            @h2 {class = "card-title"} $title
            @p {class = "author"} "by " $author
        end
        @div {class = "card-body"} $content
    end
end
@deftag macro article_card end

# Use the component
@render @article_card {
    title = "Hello",
    author = "Julia Developer",
    content = "This is a reusable component!"
}

<article class="card">
  <header>
    <h2 class="card-title">Hello</h2>
    <p class="author">by Julia Developer</p>
  </header>
  <div class="card-body">This is a reusable component!</div>
</article>

Documentation

Getting Started

Building Applications

Advanced Topics

API Reference