From be81381358cb1e168a87a5a9b94c1d4425f8aeca Mon Sep 17 00:00:00 2001 From: Tatsushi Demachi Date: Sun, 4 Jan 2015 14:24:58 +0900 Subject: [PATCH] Add operator argument to `where` template function It allows to use `where` template function like SQL `where` clause. For example, {{ range where .Data.Pages "Type" "!=" "post" }} {{ .Content }} {{ end }} Now these operators are implemented: =, ==, eq, !=, <>, ne, >=, ge, >, gt, <=, le, <, lt, in, not in It also fixes `TestWhere` more readable --- content/templates/functions.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/content/templates/functions.md b/content/templates/functions.md index 2e9cbd3c1..da794a36d 100644 --- a/content/templates/functions.md +++ b/content/templates/functions.md @@ -79,6 +79,25 @@ e.g. {{ .Content}} {{ end }} +It can also be used with an operator like `!=`, `>=`, `in` etc. Without an operator (like above), `where` compares a given field with a matching value in a way like `=` is specified. + +e.g. + + {{ range where .Data.Pages "Section" "!=" "post" }} + {{ .Content}} + {{ end }} + +Following operators are now available + +- `=`, `==`, `eq`: True if a given field value equals a matching value +- `!=`, `<>`, `ne`: True if a given field value doesn't equal a matching value +- `>=`, `ge`: True if a given field value is greater than or equal to a matching value +- `>`, `gt`: True if a given field value is greater than a matching value +- `<=`, `le`: True if a given field value is lesser than or equal to a matching value +- `<`, `lt`: True if a given field value is lesser than a matching value +- `in`: True if a given field value is included in a matching value. A matching value must be an array or a slice +- `not in`: True if a given field value isn't included in a matching value. A matching value must be an array or a slice + *where and first can be stacked* e.g.