-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Partial Template Support #77
Conversation
|
Great feature which will solve a lot of problems for us! 🚀 What was a bit tricky for me to understand at first is that there is a slight difference between supplying But that comes with a catch. In case I would invoke a template definition like this:
... I could no longer use the |
Glad that this feature will solve lots of problems for you 😃. And thank you for testing this out ❤️ This is indeed an issue. But unfortunately Go templates only accept one context parameter. I have introduced a new template function This helps you in solving the
This will create a map with keys Unfortunately I'm not able to automatically inject the targetname as the value is not known when the template functions are defined. Is this a solution which will work for you? |
Oh that is a nice solution. That would even allow us to provide multiple parts of the Inventory to a template instead of the whole Inventory (even though I'm not sure yet why one would that haha). Tested and it works. Thanks for the quick fix. |
I also tested supplying variables into the template, both "primitives" (like strings you define on the fly) as well as declaring parts of the Inventory as variable and supplying them.
With a template like this:
... you are then able to see all of those contexts getting supplied correctly (even though they get rearranged alphabetically which threw me off at first). However, you are not actually able to access
|
Thanks for repeatedly challenging the implementation 👍🏼 Given this target ---
target:
skipper:
use:
- network # not used
elements:
- this:
is:
a:
nested: map
- welcome: home This template:
And this partial
Yields the following rendered
Did I miss anything? |
I can't reproduce it either. It's possible I just messed up the local skipper vendoring. Everything works now. 🚀 |
Partial Templates allow the user to deduplicate template code by defining a template at a single place and reuse it within different templates.
{{ define "unique_tpl_name" }}
block, it should be available to use by all other templates by using the{{ template "unique_tpl_name" . }}
syntax