Expressions

In Python f-strings, the curly brackets can take not just variable names, but also Python “expressions” inside a t-string’s interpolation.

The same is true in tdom.

Python Operation

Let’s use an expression which adds two numbers together:

def main():
    """Main entry point."""
    name = "tdom"
    result = html(t"<div>Hello {name.upper()}</div>")
    return result

Simple Arithmetic

Let’s use an expression which adds two numbers together:

def main():
    """Main entry point."""
    name = "tdom"
    result = html(t"<div>Hello {1 + 3}</div>")
    return result

Call a Function

But it’s Python and f-strings-ish, so you can do even more. For example, call an in-scope function with an argument, which does some work, and insert the result:

def make_bigly(name: str) -> str:
    """A function returning a string, rather than a component."""
    return f"BIGLY: {name.upper()}"


def main():
    """Main entry point."""
    name = "tdom"
    result = html(t"<div>Hello {make_bigly(name)}</div>")
    return result