Skip to content

Make format work with map (useful for dbt) #2106

@TomAtGithub

Description

@TomAtGithub

Hey, I am using jinja with dbt and would like to prefix a list of columns in a functional way.
I am trying

{% set columns = ["title", "name"] | map("format", "prefix_%s") | join(",") %}

Unfortunately this does not work because format is not designed to be used with map.
Map passes the variables in the "wrong" order:

filters.py line 1738

def func(item: t.Any) -> t.Any:
    return context.environment.call_filter(
        name, item, args, kwargs, context=context
    )

format uses this syntax:

{{ item % args }}
# Example
{{ "Hello, %s!" % name }}

but to work with map it should be something like this:

{{ args % item }}

It would be nice to have it, even though its just syntactic sugar

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions