Skip to content
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

Access parent element in loop with same name as child element #41

Closed
eerimez opened this issue May 7, 2020 · 2 comments
Closed

Access parent element in loop with same name as child element #41

eerimez opened this issue May 7, 2020 · 2 comments

Comments

@eerimez
Copy link

eerimez commented May 7, 2020

Given the following YAML:

---
name: cashew
data: hello
projects:
  - name: mustache
  - name: pystache

And the following Mustache:

Parent Name: {{name}}
{{data}}
{{#projects}}
    Top Child Data: {{data}}
    Parent Name: {{#.}}{{name}}{{/.}}
    Child Name: {{name}}
{{/projects}}

I am getting the following output:

Parent Name: cashew
hello
    Top Child Data: hello
    Parent Name: mustache
    Child Name: mustache
    Top Child Data: hello
    Parent Name: pystache
    Child Name: pystache

How can I access the top level object element from within the loop with the same name as a child's element?

@eerimez
Copy link
Author

eerimez commented May 8, 2020

Is this project maintained? Is just best to use Go's text/template?

@cbroglie
Copy link
Owner

Yes, this code is maintained. You should use this package if you want to use the mustache templating language from Go. If your only requirement is templating in Go, then either solution is fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants