Skip to content

Language ​

Herb reads the HTML and the ERB in a template as one document. Most of what that gives you needs nothing new in your templates. The linter, the formatter, the language server and the engine all work on the .html.erb files you already have.

For templates whose parts update in the browser after the page loads, Herb adds a small amount of syntax of its own. Directives are ERB comments and actions are HTML attributes, so a template that uses them still reads as ordinary HTML+ERB.

ConstructWritten asReference
Templates.html.erb, .herbTemplates
ERB syntax<%= %>, <% if %>, <%# %>ERB Syntax
State<%# herb:state (open: false) %>State
Actionsdata-herb-toggle="open"Actions
Keys and collections<%# herb:key message.id %>, data-herb-intoKeys and collections
Slots<%# herb:slots client %>Slots
Components<Fragment>, <Async>, <Lazy>, <Fallback>Components
Scoped styles<style scoped>Scoped styles
Strict locals<%# locals: (title:) %>Strict locals

These pages are reference. Each one says what a construct does, what it accepts and what it rejects. For a guided introduction that builds a working page in a Rails app, start with ReActionView, which wires everything here into Action View.

Slots are experimental

State, actions, keys, slots, components and scoped styles are experimental in Herb ^0.11.0. The markers they write into the page, the payload the server sends and the client API may change between releases. The engine prints the same notice when it compiles a template with slots.

Released under the MIT License.