1. Docs
  2. Secrets & Configuration
  3. Environments
  4. Environment Definition Syntax
  5. Built-in Functions
  6. fn::eval

fn::eval

    The fn::eval built-in function evaluates a template expression in the context of the current environment. Together with fn::template, it enables late binding — the ability to define reusable expressions in one environment and evaluate them with different values in another.

    Declaration

    fn::eval: template-reference
    

    Parameters

    PropertyTypeDescription
    template-referenceanyA reference to a value defined with fn::template. Typically an interpolation like ${environments.org.defn.my-template}.

    Returns

    The result of evaluating the referenced template in the context of the calling environment. The template’s interpolations are resolved using the values available in the environment where fn::eval is called, not where the template is defined.

    Example

    Reusable greeting template

    This example shows how to define a template in one environment and evaluate it in multiple environments with different values.

    Template environment (example/defn)

    values:
      hello:
        fn::template: Hello ${name}!
    

    The fn::template expression defines a template that references ${name}. The interpolation is not resolved in this environment — it is deferred until a consumer evaluates it with fn::eval.

    Consumer environment A (example/a)

    values:
      name: "foo"
      example:
        fn::eval: ${environments.example.defn.hello}
    

    Consumer environment B (example/b)

    values:
      name: "bar"
      example:
        fn::eval: ${environments.example.defn.hello}
    

    Parent environment

    values:
      a: ${environments.example.a}
      b: ${environments.example.b}
    

    Evaluated result

    {
      "a": {
        "example": "Hello foo!",
        "name": "foo"
      },
      "b": {
        "example": "Hello bar!",
        "name": "bar"
      }
    }
    

    Environment A resolves the template with name: "foo", producing "Hello foo!". Environment B resolves the same template with name: "bar", producing "Hello bar!".

    • fn::template — defines a template expression for deferred evaluation.