user: Describe Path Templates from the Blender manual or Python API, including usage steps and snippets.

assistant: Path templates substitute *template expressions* (written `{abcd}`, where
“abcd” is a *variable* name) in a filepath when the path is used.

For example, if the currently open blend file is `dance.blend` and the render
output path is set to this:

```
//my_render_dir/{blend_name}.png
```

Then when rendering, Blender will treat the path as:

```
//my_render_dir/dance.png
```

With `{blend_name}` getting replaced by the `dance` from `dance.blend`.

This substitution happens internally at time of use (e.g. while rendering), so
the template syntax will remain as-is in the path field.

### Available Variables

The following variables are currently available in template expressions.

Available in all paths that support template expressions:

`blend_name`:
:   The currently open blend file’s name (without the .blend).

`blend_dir`:
:   Path up to (but not including) the currently open blend file.

`blend_name_lib`:
:   Like `blend_name`, except that for path properties on
    library-linked data-blocks it will be the name of the library blend file
    that the data-block comes from.

`blend_dir_lib`:
:   Like `blend_dir`, except that for path properties on
    library-linked data-blocks it will be the path to the library blend file
    that the data-block comes from.

Available only in render output paths (including in the compositor File Output node):

`fps`:
:   The frames per second of the current scene.

`resolution_x / resolution_y`:
:   The x and y resolution of the rendered image.
    This factors in the resolution scale as well, so if the scene resolution is
    1000x600 and the scale is 50%, then `resolution_x` and `resolution_y`
    will be 500 and 300, respectively.

`scene_name`:
:   Name of the current scene.

`camera_name`:
:   Name of the current render camera.

Available only in path properties on a node:

`node_name`:
:   The name of the node that the path property is on.

### Syntax

A basic template expression simply wraps a variable name with curly braces:

```
dance_{fps}.png
```

#### Format Specifiers

Template expressions can also include a format specifier.
Format specifiers instruct Blender how to format the substituted value.
They are written after a separating colon, like this:

```
dance_{fps:FORMAT}.png
```

Format specifiers currently can only be used with variables that represent
numerical values, not string values. The available format specifiers are:

- `dance_{fps:###}.png`: format as an integer with at least 3 digits.
- `dance_{fps:.###}.png`: format as a floating point number with exactly 3
  digits after the decimal point.
- `dance_{fps:###.##}.png`: format as a floating point number with at least 3
  digits for the integer part and exactly 2 digits for the fractional part.

In all cases, the number of hash symbols (`#`) indicates the desired number of
digits.

For example, if the fps is 29.97, then:

- `dance_{fps:###}.png` -> `dance_030.png`
- `dance_{fps:.###}.png` -> `dance_29.970.png`
- `dance_{fps:###.##}.png` -> -> `dance_029.97.png`

Note that the values are properly rounded for the given number of digits.

If no format specification is given, default formatting for the named variable
is used (e.g. floating point for fps, integer for resolution).

### Escape Sequences

Because `{` and `}` are used for template expressions in paths that support
them, when a literal `{` or `}` is desired in such a path they must be
escaped by writing them double:

- `{{` translates to a single `{` in the final path.
- `}}` translates to a single `}` in the final path.

For example:

- `my_weird}}_{{path.png` -> `my_weird}_{path.png`
- `//my_render_{{dir}}/{blend_name}.png` -> `//my_render_{dir}/dance.png`
- `//my_render_dir/{{{blend_name}}}.png` -> `//my_render_dir/{dance}.png`

### Errors

Paths that support templates can have template errors, which prevent the
path from being processed.

For example, in the following path:

```
//my_render_dir/{blend_name.png
```

The expression `{blend_name` isn’t properly closed, which will result in an
error.

When there are template errors in a path, the path field will be highlighted red
in the UI:

[image reference removed]

Hovering over the path field will pop up a tooltip that contains a list of the
template errors encountered in that path:

[image reference removed]