Support template base directories
ahall opened this issue · 3 comments
If engine base directory is e.g. /tmp/templates
Then extends layouts/basic
Would mean /tmp/templates/layouts/basic.
Ideally adding this functionality would not break existing code so one could keep using ./template and ../template respectively.
This is first mentioned in #7.
One thing I think we would improve if you could specify a base directory where your engine looks for templates so instead of doing include ../helpers/blah you could do: include helpers/blah and you tell the engine that your template base dir is /path/to/basedir and it only ever lets you look inside there.
Not sure how that could be implemented without a breaking change unless you add it to the generator. What you really want is an area where templates are as its own sandbox and reference stuff that way e.g. extends layout, include helpers/my_helper. You could add it as a property to the generator and if the property is set then use the sandbox, otherwise default behaviour. Or even add a template locator function a user of the library can implement and pass in. Let me know what you think and if you think it makes sense we could close this issue and open a new one.
@ahall Hi, sorry for the late reply. I added this feature on Gold. You can set a base directory of Gold templates by calling Generetor.SetBaseDir()
:
var g = gold.NewGenerator(true).SetBaseDir("/path/to/basedir")
And if you call include foo/bar
or extends foo/bar
in Gold templates, Gold reads a template file foo/bar.gold
under the base directory.
Please get the latest version of Gold and check this feature.
Thanks!
Simply fantastic, works a treat. Thanks for this.