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

tpl: add now function #2859

Merged
merged 1 commit into from Jan 1, 2017
Merged

tpl: add now function #2859

merged 1 commit into from Jan 1, 2017

Conversation

nishanths
Copy link
Contributor

@nishanths nishanths commented Dec 31, 2016

Add a timeNow template function that returns the current time as
time.Time. Also, update related docs.

Don't know what the right way to test this change is (if necessary), so I'm open to suggestions.

Personally, I'm looking to use use the unix timestamp of the current time in the query string for cache busting in a theme.

<link rel="stylesheet" href="/css/reset.css?t={{ timeNow.Unix }}">

I'm sure hugo users will come up with other creative uses for current time.

@CLAassistant
Copy link

CLAassistant commented Dec 31, 2016

CLA assistant check
All committers have signed the CLA.

@nishanths nishanths changed the title tpl: add timeNowUTC tpl: add timeNow Dec 31, 2016
@moorereason
Copy link
Contributor

time.Now is already accessible on the Page object.

However, I've started a discussion referencing this PR: https://discuss.gohugo.io/t/4968

@nishanths nishanths changed the title tpl: add timeNow tpl: add now function Dec 31, 2016
@nishanths
Copy link
Contributor Author

Updated the function name to now

@@ -2186,6 +2186,7 @@ func initFuncMap() {
"substr": substr,
"title": title,
"time": asTime,
"now": func() time.Time { return time.Now() },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this fits fine next to time, but the rest of them are alphabetic ordered.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, thanks

Add a now template function that returns the current time as time.Time.
Also, update related docs.
@bep bep merged commit cabc6b3 into gohugoio:master Jan 1, 2017
@nishanths nishanths deleted the time-now-utc branch January 1, 2017 09:58
@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants