๐ค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.
a.foo#bar(class="foobar", class="fooz baz") Incredible!
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:
func Button(disabled bool)
button.bar
if disabled
&.foo(disabled)
> Click me
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:
func Example()
button
> Click me!
&(disabled)
The above won't compile:
error: use of & after writing to element's body
> example.corgi:5:3
|
3 | button
| ~~~~~~ in this element
4 | > Click me!
| ~~~~~~~~~~~ you wrote an arrow block here
5 | &(disabled)
| ^ so you cannot place an & here
suggestion: you can only use the & operator before you write to the body of an element.
The div
Shorthand
div
Shorthanddiv
s 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?