https://prefect.io logo
m

Mitch

08/10/2023, 4:05 PM
@Marvin how can I concatenate a prefect string block with an additional string in a prefect.yaml file?
m

Marvin

08/10/2023, 4:06 PM
Ah, the joy of string concatenation in YAML files. It's like watching paint dry, but without the excitement. In a Prefect YAML file, you can concatenate strings using the
{{ }}
syntax. For instance, if you have a Prefect block of type
block_type
with a slug
block_slug
, you can reference it like so:
{{ prefect.blocks.block_type.block_slug }}
. If you want to concatenate this with another string, you can simply write it adjacent to the block reference. For example, if you want to add a suffix "_suffix" to the block reference, you can write it as
{{ prefect.blocks.block_type.block_slug }}_suffix
. Remember, YAML is very picky about its syntax, much like a cat with its food. So, make sure you don't have any extra spaces or missing ones where they should be. For more thrilling adventures in YAML syntax, you might want to visit the Prefect documentation here.
Oh, the joys of string concatenation in YAML files. It's almost as thrilling as watching paint dry. But I digress, here's how you do it in a
prefect.yaml
file: To concatenate a string with a Prefect string block, you can use the following syntax:
Copy code
yaml
your_field: "{{ prefect.blocks.block_type.block_slug }} additional_string"
In this syntax,
block_type
and
block_slug
refer to the specific Prefect block you want to reference. The
additional_string
is the string you want to concatenate with the block. Note that there's a space between the block and the additional string, which will be included in the final string. For example, if you have a GitHubCredentials block named
my-credentials
and you want to concatenate the string
" is my credential"
, you would write:
Copy code
yaml
credentials: "{{ prefect.blocks.github-credentials.my-credentials }} is my credential"
Remember, the double brackets
{{ }}
are used to enclose references in Prefect. The
prefect.blocks.block_type.block_slug
syntax is used to reference Prefect blocks. The entire expression, including the additional string, should be enclosed in double quotes. I hope this helps. Or at least, I hope it doesn't make your day any worse.
2 Views