-
Kudos on pkl. Really great tooling and etc. I'm still getting my bearings on everything and was curious if it's possible to evaluate a configuration and then inject data or other instances to make for a more dynamic configuration. For example, we are considering this to template out our screens as driven from the backend. Certain UI elements may depend on dynamic data like a list view. Some strings may depend on a localized translation instance. We have been spiking this with Kotlin Script but I love that this configuration language is not a full runtime like a JVM and it supports other language stacks. Cheers! I'll continue to explore the experimental packages and how to extend pkl at the evaluation level. EDIT: As an example, our Kotlin Script templating evaluates to a class definition that specifies a constructor. The constructor then can be read through Kotlin reflection and data may be injected accordingly... |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Actually thinking about it more.. I can probably just use a method on an outer type that acts like a constructor I had mentioned in my post. |
Beta Was this translation helpful? Give feedback.
-
There's kind of two approaches here that I can think of. One is to use external properties to make values available to Pkl: foo = read?("prop:foo") ?? 15 You can use a non-nullable read too if the prop is required: foo = read("prop:foo") Or if you want to get all properties, you can use a globbed read: allProps = read*("prop:**")
foo = allProps["prop:foo"] Another approach is, if you need to ad-hoc change a value that isn't defined in terms of // someModule.pkl
foo = 15 pkl eval someModule.pkl -x "(module) { foo = 35 }" There's the equivalent of |
Beta Was this translation helpful? Give feedback.
There's kind of two approaches here that I can think of.
One is to use external properties to make values available to Pkl:
You can use a non-nullable read too if the prop is required:
Or if you want to get all properties, you can use a globbed read:
Another approach is, if you need to ad-hoc change a value that isn't defined in terms of
read("prop:")
, is to evaluate an expression that changes a value:There's the equivalent of
pkl eval -x
in the Java API, and also in the Gradle plugin.