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

Add after template function to complement first #1200

Closed
wants to merge 5 commits into from

Conversation

ariejan
Copy link
Contributor

@ariejan ariejan commented Jun 10, 2015

The first template function allows the user to select the first X items of an array. I have a use case where I want those X first items, but I also want the rest of the items after X for separate processing. after adds this functionality.

{{ range after 10 .Data.Pages }}
    {{ .Render "title" }}
{{ end }}

There is one open question and that's the one of naming things 😈
Is after properly named? I chose it over remaining, as the supplied limit would not make sense. Are there any other candidates that need to be considered? /cc @spf13 what's your opinion on this?

Where `first` will return the first N items of a rangeable list,
`after` will return all items after the Nth item.

This allows the user to do something with the first N items and
something different with the remaining items after N.
@@ -177,7 +177,7 @@ func Substr(a interface{}, nums ...interface{}) (string, error) {
}

var start, length int
toInt := func (v interface{}, message string) (int, error) {
toInt := func(v interface{}, message string) (int, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Change made by gofmt.

@ariejan
Copy link
Contributor Author

ariejan commented Jun 10, 2015

@spf13 gofmt also made some minor tweaks to the code that snuck into my commits. Do you want me to pull them out before considering this for merging?

@spf13
Copy link
Contributor

spf13 commented Jun 10, 2015

no. It's all good. Go fmt is a good thing.

@spf13
Copy link
Contributor

spf13 commented Jun 10, 2015

I feel like we need a last as well following this change.

@ariejan
Copy link
Contributor Author

ariejan commented Jun 10, 2015

@spf13 seems like a good idea, while I'm at it. Give me few moments... 🕦

`last` allows the user to select the last X items of
and array.
@ariejan
Copy link
Contributor Author

ariejan commented Jun 10, 2015

@spf13 pending tests, here's your last :shipit:

@bep
Copy link
Member

bep commented Jun 15, 2015

Merged in cc9536e Very useful. And with docs AND tests. Me like.

@bep bep closed this Jun 15, 2015
@wayneashleyberry
Copy link

❤️

@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 27, 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.

4 participants