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

Parse included templates #271

Closed
mbrgm opened this Issue Aug 10, 2013 · 5 comments

Comments

Projects
None yet
5 participants
@mbrgm

mbrgm commented Aug 10, 2013

As a user
I want to be able to include templates in other templates
In order to build DRY modular templates

This is inspired by the bento project. My proposal is to parse templates, which were included using Go's {{ template "foo" }}.

Example

templates/common.json

{
    "ssh_port": 22,
    ...
}

templates/ubuntu/ubuntu.json

{
    {{ template "../common" }}
    "guest_os_type": "Ubuntu_64",
    ...
}

templates/ubuntu/13.04-server-amd64.json

{
    {{ template "ubuntu" }}
    "iso_url": "iso/ubuntu-13.04-server-amd64.iso",
    ...
}

Result

This would yield the following template:

{
    "ssh_port": 22,
    "guest_os_type": "Ubuntu_64",
    "iso_url": "iso/ubuntu-13.04-server-amd64.iso",
    ...
}

Issues

The above approach leads to invalid json files. So maybe the templates with include statements should have a different filetype, e.g. .json.templ. Another possibility would be to not use the {{{ template "foo" }}} syntax and introduce an "include" key in json templates, which specifies the template file to be included, e.g. "include": "../common".

@mbrgm

This comment has been minimized.

Show comment
Hide comment
@mbrgm

mbrgm Aug 13, 2013

What's the kind of additional info I should provide?

mbrgm commented Aug 13, 2013

What's the kind of additional info I should provide?

@mitchellh

This comment has been minimized.

Show comment
Hide comment
@mitchellh

mitchellh Aug 14, 2013

Member

This is a feature I definitely want to support, but I haven't given it the proper amount of thought yet. It'll come sooner rather than later but I ask your patience.

Member

mitchellh commented Aug 14, 2013

This is a feature I definitely want to support, but I haven't given it the proper amount of thought yet. It'll come sooner rather than later but I ask your patience.

@pierreozoux

This comment has been minimized.

Show comment
Hide comment
@pierreozoux

pierreozoux Aug 21, 2013

I agree it would be great! Unfortunately, I don't have Go Knowledge yet to help on this right now... I can test!

pierreozoux commented Aug 21, 2013

I agree it would be great! Unfortunately, I don't have Go Knowledge yet to help on this right now... I can test!

@kouk

This comment has been minimized.

Show comment
Hide comment
@kouk

kouk Oct 3, 2014

Contributor

Any news or thoughts about this? It would definitely be a very useful feature.

Contributor

kouk commented Oct 3, 2014

Any news or thoughts about this? It would definitely be a very useful feature.

@sethvargo sethvargo added the core label Feb 24, 2015

@mitchellh

This comment has been minimized.

Show comment
Hide comment
@mitchellh

mitchellh May 29, 2015

Member

I was wrong in my initial comment, this never came :) And we're not planning this in the short term. We've gotten a lot of mileage without it and for now we're just recommending folks pre-process and output JSON to do this. Sorry!

Member

mitchellh commented May 29, 2015

I was wrong in my initial comment, this never came :) And we're not planning this in the short term. We've gotten a lot of mileage without it and for now we're just recommending folks pre-process and output JSON to do this. Sorry!

@mitchellh mitchellh closed this May 29, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment