Add query-support on non-existing page params in where template func #1232

Closed
ashishthedev opened this Issue Jun 27, 2015 · 0 comments

Comments

Projects
None yet
2 participants
@ashishthedev

Use Case:

There are about 200 pages in the website.
But some pages like "privacy", "about" and "terms and conditions" are appearing on the home page.
You dont want these pages on home page, so you declare a page specific param on these pages:

front matter:

+++
...
notOnHomePage = "true"
+++

and in index.html

...
{{range first 10 (where .Paginator.Pages ".Params.notOnHomePage" "!=" "true")}}
...

But now not even single post is shown on the homepage.

Original Discussion:
http://discuss.gohugo.io/t/how-to-filter-pages-on-homepage-based-on-page-params/1369

@bep bep changed the title from "where" functionality is broken when page specific parameter is not present on the pages. to Add query-support on non-existing page params in where template func Jun 27, 2015

@bep bep added the Enhancement label Jun 27, 2015

tatsushid added a commit to tatsushid/hugo that referenced this issue Jun 29, 2015

Add nil comparison to where tpl function
`where` template function's internal condition check function always
returns `false` when a target value doesn't exist or it's nil value but
this behavior makes it difficult to filter values which doesn't have a
particular parameter.

To solve it, this adds nil value comparison to the function.
`where Values ".Param.key" nil` like clause can be used for the case
above.

Only "=", "==", "eq", "!=", "<>", "ne" operators are allowed to be used
with `nil`. If an other operator is passed with `nil`, the condition
check function returns `false` like before.

Fix #1232

@bep bep closed this in dd732e8 Jun 29, 2015

tychoish added a commit to tychoish/hugo that referenced this issue Aug 13, 2017

Add nil comparison to where tpl function
`where` template function's internal condition check function always
returns `false` when a target value doesn't exist or it's nil value but
this behavior makes it difficult to filter values which doesn't have a
particular parameter.

To solve it, this adds nil value comparison to the function.
`where Values ".Param.key" nil` like clause can be used for the case
above.

Only "=", "==", "eq", "!=", "<>", "ne" operators are allowed to be used
with `nil`. If an other operator is passed with `nil`, the condition
check function returns `false` like before.

Fix #1232
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment