๐ŸคAttributes

Writing attributes is very straight-forward. Simply put them in parentheses directly behind the element's name. You can assign an attribute any printable expression you want.

a(href="https://github.com/mavolin/corgi") Corgi's GitHub

To write boolean attributes omit the value or set it to a boolean:

button(disabled) Click me!
button(disabled=true) Click me!
- b := false
button(disabled=b) Click me!

Attributes can even span multiple lines.

input(
  type="checkbox",
  name="agreement",
  checked,
)

Classes and IDs

Classes and IDs, being incredibly common, even get their own short form.

Corgis are smart doggos! Corgi will combine multiple class attributes and short forms into a single class attribute. This does not work for other attributes.

a.foo#bar(class="foobar", class="fooz baz") Incredible!

The &-Operator

One of the features that sets corgi apart from other template engines is its &-operator.

You can use it to add an attribute to the element from its body. This is super useful, if your attribute is conditional:

func Button(disabled bool)

button.bar
  if disabled
    &.foo(disabled)
  > Click me

The div Shorthand

divs are incredibly common. Therefore, as long as your div has at least one class or an id, you can write .foo or #bar to produce a div.

div.foo#bar All
.foo#bar the
#bar.foo same

Last updated

Was this helpful?