mirror of
https://github.com/apple/pkl.git
synced 2026-01-11 22:30:54 +01:00
Read resources default value #199
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @jjuliano on GitHub (Sep 3, 2024).
I have a template that reads an optional resource.
field: String? = read("env:STRING")However, this causes an error when the resource is read because
env:STRINGneeds to exist, so I added a default value.field: String? = read("env:STRING") ?? "DEFAULT_STRING"The code above still fails and exits when attempting to read the resource.
@shurshun commented on GitHub (Sep 3, 2024):
This one should work:
field: String? = read?("env:STRING") ?? "DEFAULT_STRING"