Skip to content

Templating with Eta

There are multiple ways to use Eta in infoboxes.

Templates

Any markdown files in the folder designated in the Template Folder setting will be available as infobox templates. These templates are loaded by invoking their name in the zeroth argument of a table, prefixed by an !. The contents of that template are then rendered by Eta before being parsed by the infobox renderer.

When invoking a template, arguments with no prefix will be passed to the eta scripting context, where the argument ID is the key and the argument content is the value. !, :, and @ arguments added here will be appended to the rendered arguments, and processed normally.

In a non-template infobox, you may pass values that will be available in any ~= dynamic content contexts by prefixing them with a $ as you would an element argument.

Templates are processed entirely before the main process, meaning that their output is interpreted as the code block contents. Therefore, normal parsing rules apply. Currently, only one such template can be used in a table at a time, but partials can define argument contents.

Partials

Markdown files in the folder defined in the setting Partials Folder will be available as partials within Eta.

In an element argument, passing $include="name" will cause the content to be prepended with the partial name. Values passed in brackets {} that are prefixed by ! will be available within the partial's context in box.val.

For example, take the following preset:

    "ex" : {
        "element" : "td",
        "para" : { 
            "eta" : "true",
            "include" : "partial-example"
        }
    }

With the file partial-example.md in the partials folder: <%= box.val.foo %> When invoked like so: | !ex {!foo=Fum} Is equivalent to: | :td {$include=partial-example !foo=Fum} ~= OR | :td ~= <%= include("partial-example", {"box": {"vals": {"foo": "Fum"}}}) %> And renders as: | :td = Fum

Currently, there is no way to define arguments within a partial.

Eta JS

Within a template, you may use the Eta syntax to write javascript. The JS context has access to some information about the infobox, including the variables passed to it, in the box object. Any passed values are in box.val. Here is an example:

| $title = Foo
| !t ~= <%= box.val.title %> 

Resolves as: !t = Foo

box.file contains functions that return information about the file the infobox is in.

  • box.file.title()
  • box.file.path()
  • box.file.stat()
  • box.file.frontmatter()

The helper function box.hasValue(string) returns true or false, useful for optional box values that only render if a value is passed to the tempalte.

Also, box.obsidian provides access to the obsidian module.

This feature and the syntax for its use is not final.