- Notifications
You must be signed in to change notification settings - Fork299
Accessing amended values without declaring locals#940
-
I'm trying to create a template with certain constant values that'd I'd like to be accessible to users of the template. Is there a way to do this without creating a local in the amended module? Here's a very minimal example of what I'm talking about // template.pklmoduletemplateconstvalue ="some constant value"config:Listing<String> // config.pklamends"template.pkl"config =newListing{"foo""bar""baz-\(value)"} Trying to evaluate this returns an error: I can sort of overcome this by defining a local property: // config2.pklamends"template.pkl"localval = valueconfig =newListing{"foo""bar""baz-\(val)"} However, in more complex scenarios this becomes very inconvenient. When you have several levels of amended templates for instance. Needing to create a local property in every place in the template hierarchy where you need to use the value quickly becomes a problem. Is there a better way to accomplish this? |
BetaWas this translation helpful?Give feedback.
All reactions
You can access this usingmodule
:
config {"foo""bar""baz-\(module.value)"}
Replies: 1 comment 5 replies
-
You can access this using config {"foo""bar""baz-\(module.value)"} |
BetaWas this translation helpful?Give feedback.
All reactions
-
Thanks! That works great. I had no idea As a follow up, is there a way to do something similar for amended objects? |
BetaWas this translation helpful?Give feedback.
All reactions
-
Can you elaborate on that? Do you have an example? |
BetaWas this translation helpful?Give feedback.
All reactions
-
I realized that the amending syntax for objects forces you to give them an identifier in scope, so this isn't an issue. i.e in tortoise = (dodo) {name ="Galápagos tortoise"taxonomy {`class` ="Reptilia" }}
|
BetaWas this translation helpful?Give feedback.
All reactions
-
Gotcha. Also, there is tortoise {name ="\(super.name) tortoise"taxonomy {`class` ="Reptilia" }} Note that |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
-
I found this and I have the feeling my case / question is similar but I don't get it to work. something .. somethinglocalbaseHeaderComment ="# Do not modify!\n# This file was generated from a template using https://github.com/StefMa/pkl-gha"headerComment:String?=nulllocal finalHeaderComment:String=if (headerComment!=null)"\(headerComment)\n\n"+ baseHeaderCommentelse baseHeaderCommentoutput {text ="\(finalHeaderComment)\n\n\(super.text)"renderer =newYamlRenderer{converters { ["headerComment"]= (headerComment:String?)->null } }} My consumercan (don`t have to) override it like this: amends"../GitHubAction.pkl"headerComment =""" # SPDX-FileCopyrightText: Copyright line here # # SPDX-License-Identifier: License here """ However, I don't like that I have the I also thought introducing a class like An advice how to model this would be great. |
BetaWas this translation helpful?Give feedback.