โœ๏ธInterpolation

Expression Interpolation

Corgi has a special syntax that allows you to interpolate expressions inside your text. Simply write #{myExpression} inside any text to evaluate the expression and include it in the text.

import "mypackage"

- func sayWork() string {
    return "work"
  }

func Interpolation(myArg string)

p
  > I can easily interpolate #{myArg} or
    even a global constant #{mypackage.Constant}.
p
  > I can even interpolate literals
    like #{123} or #{"a" == "b"}.
p And functions #{sayWork()} too.

All expressions are escaped before getting printed.

If you ever just want to type a raw # inside your text or strings, write ##. The # is the only character in corgi that needs escaping.

p Look, a ##!

becomes

<p>Look, a #!</p>

Text Interpolation

You can also interpolate text.

This might sound useless at first, but it allows you to add trailing spaces to lines.

If you add a ! after the #, the text won't be escaped. This is super useful to use HTML character escapes.

Interpolated Elements

Sometimes you want to use a fairly short element directly in text. For that, you can use interpolated elements:

To use an expression in an interpolated element, simply swap out the [brackets] for {curly braces}. You can write everything that you can write when interpolating expressions.

You can also add classes and attributes to the interpolated element. Don't overdo it though, long chains of classes and attributes hurt readability.

String Interpolation

Corgi also allows expression interpolation in strings:

Last updated

Was this helpful?