logoalt Hacker News

Type-safe HTML templating in Zig

29 points • by lukaslalinsky • today at 5:02 AM • 8 comments • view on HN

Comments

Humphrey • today at 5:43 AM

I love the idea! I could imagine something similar created for other languages too. Perhaps written in a way that a template could be reused i, let's say Django, and a JS React frontend. With all the type-safety that tsx provides.

➕ show 3 replies
fergie • today at 5:56 AM

W3C: Why can't we just have <includes src="./header.html"> and be done with it?

➕ show 1 reply
slopinthebag • today at 5:21 AM

one thing i love about rust's macros is that you can accomplish this without needing a separate file type or inventing syntax

   #[component]
   pub fn HomePage(user: Option<User>) -> Element {
      rsx! {
         Layout { 
            title: "Home",
            if let Some(u) = user {
               h1 { "Welcome back, {u.name}!" }
               a { href: "/users/{u.id}", "Your profile" }
            } else {
               h1 { "Welcome, guest!" }
               a { href: "/login", "Log in" }
            }
         }
      }
   }
➕ show 4 replies
thetexaslawdog • today at 5:54 AM

[flagged]