gnormal / gnorm

A database-first code generator for any language
https://gnorm.org
Other
487 stars 40 forks source link

Add config to template data #22

Closed pgwa closed 6 years ago

pgwa commented 6 years ago

I could not find a way to get config vars from gnorm.toml . For example, in one of my templates I needed the value of IncludeTables from gnorm.toml. Maybe something like {{.Config.IncludeTables}}. or {{config "IncludeTables"}}.

natefinch commented 6 years ago

Great idea, definitely will do that. Also gives the user the ability to add extra data to the config that could be passed to the template.

gernest commented 6 years ago

While I think adding some of config settings to templates context is a good thing. I don't think it makes sense to jam extra data into the config since, well it is config.

Probably one option is to allow stating of .toml files that have extra data to be added to context and they will be loaded and passed to the templates accordingly.

So, I favor exposing some of the config values to template context not the whole config object as is.

natefinch commented 6 years ago

The reason I'm thinking of jamming extra data in the config is that it mimics what Hugo does, and it gives people a one-stop-shop for customizing the output of their templates. Like Hugo, I hope people will create templates to share with others, that then people can customize via the configuration file. Why have two configuration files when you could just have one?

gernest commented 6 years ago

Fair point, last time i used hugo was a long time ago, so I can't say much about that.

If the goal is to allow the templates authors to share, what happens if there is shared templates specific data? Not all data is configuration.

I get it to have one config with everything makes things a lot easy to manage.

natefinch commented 6 years ago

This is fixed by #25 :) . And it's in the v0.2 release