๐ค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<a href="https://github.com/mavolin/corgi">Corgi's GitHub</a>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!<button disabled>Click me!</button>
<button disabled>Click me!</button>
Attributes can even span multiple lines.
input(
type="checkbox",
name="agreement",
checked,
)<input
type="checkbox"
name="agreement"
checked
>Classes and IDs
Classes and IDs, being incredibly common, even get their own short form.
a.foo#bar(class="foobar", class="fooz baz") Incredible!<a class="foo foobar fooz baz" id="bar">Incredible!</a>The &-Operator
&-OperatorOne 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:
You can only place the &-operator before you write text or another element to the element's body. If you don't, the compiler will complain:
The above won't compile:
The div Shorthand
div Shorthanddivs 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.
Last updated
Was this helpful?