-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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
create: Use archetype template as-is as a Go template #3605
Conversation
This commit removes the fragile front matter decoding, and takes the provided archetype file as-is and processes it as a template. This also means that we no longer will attempt to fill in default values for `title` and `date`. The upside is that it is now easy to create these values in a dynamic way: ```toml +++ title = {{ .Name | title }} date = {{ .Date }} draft = true +++ ``` You can currently use all of Hugo's template funcs, but the data context is currently very shallow: * `.Type` gives the archetype kind provided * `.Name` gives the target file name without extension. * `.Path` gives the target file name * `.Date` gives the current time as RFC3339 formatted string The above will probably be extended in gohugoio#1629. Fixes gohugoio#452 Updates gohugoio#1629
I agree that the implementation looks much cleaner now 👍
I would like to propose to extend the list as follows:
The intention of this list was to extend it with variables that might be used in an archetype template. Furthermore, I tried to keep the overhead low. Hugo shouldn't parse all existing pages in order to know what taxonomies etc already exists. Please correct me if my assumption of the internal implementation of some of the aforementioned vars is in conflict with this goal. For the sake of interest: is it possible to call partials within a front matter template? |
Yes, but that sounds a little bit strange...? But I don't see any problems with it, do you (we could remove the
|
Strange? Maybe. I don't think users will have such complex front matter templates that they would have the need to split it up into partials. Should we remove it? I don't see no reason why it should be bad to leave it. Currently, we can say you can use every template function which a reference to them without having to list exceptions.
Personally I don't have any.
I've looked twice at the available variables and they don't provide not many usecases in a front matter. Let's forget this proposal |
@digitalcraftsman look at my second commit. I rethought the "File" question; it will not have |
This looks like a good alternative. |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This commit removes the fragile front matter decoding, and takes the provided archetype file as-is and processes it as a template.
This also means that we no longer will attempt to fill in default values for
title
anddate
.The upside is that it is now easy to create these values in a dynamic way:
You can currently use all of Hugo's template funcs, but the data context is currently very shallow:
.Type
gives the archetype kind provided.Name
gives the target file name without extension..Path
gives the target file name.Date
gives the current time as RFC3339 formatted stringThe above will probably be extended in #1629.
Fixes #452
Updates #1629