My nested where clause is not working

I have a partial where I want to display content meeting two conditions:

<ul class="itemize ">
    {{ range (where (where .Data.Pages "Params.pinned" "==" nil) "Section" "!=" "").ByDate.Reverse }}
    <li>
        <span class="date">
            {{ .Date.Format "2006/01/02" }}
        </span>
        <span>{{ .Title | markdownify }}.</span>
    </li>
    {{ end }}
</ul>

The condition for Section is met, but the one for pinned is not. I halve also tried: where .Data.Pages ".Params.pinned" "==" nil, where .Data.Pages "Params.pinned" "!=" true, they do not work. I keep getting in the list, items that have .Params.pinned set to true.

In my content, not all pages have pinned set. I want to get them! What am I doing wrong?

More info

This might be useful, I had a code before which was kinda working:

{{ range (where .Data.Pages "Section" "!=" "") }}
    {{ if not .Params.pinned}}
    <li>
        <span class="date">
            {{ .Date.Format "2006/01/02" }}
        </span>
        <span>{{ .Title | markdownify }}.</span>
    </li>
{{ end }}

This was working! But I want to reorder and reverse, and the code above does not guarantee that the correct items will be picked. I need to move the condition on pinned in the where clause.

In the code block you posted it should be .Params.pinned

It seems that you are missing the dot in the front.

Hi and thanks for commenting. I wrote down in the question that with or without the dot, the result is unfortunately the same.

Sorry I had not read beyond the code block.

Locally I cannot reproduce what you report.

In a sample project with the following structure:

content
├──about[with-pinned-true].md
├── section-1
|       └── pinned-true.md
└──section-2   
        └── unpinned.md      

I am only rendering the title of /section-2/unpinned.md/ with the code you posted.

It seems that something else is going on and either me or the others will need to see a git repo with the source code of your project to reproduce the issue locally. If you cannot share your project then upload a minimal version with dummy content.

I find IT easier to combine where with union and/or intersect for this.

1 Like

I see… Either I have something clearly stupid going on or there is an issue somewhere. Problem is I am not using Hugo 100%, I am using Blogdown. I hope there is not an issue with Blogdown interfacing with Hugo :frowning: I will try to investigate a bit more

I have edited the question with some useful info

I’ve never used Blogdown but there shouldn’t be a difference regarding the templates. Isn’t it just a package for R Markdown?

Anyway to follow up on the suggestion that was made above try:

{{ $unpinned := intersect (where (where .Data.Pages ".Params.pinned" "==" nil) "Section" "!=" "") .Data.Pages }}
{{ range $unpinned.ByDate.Reverse }}
    <li>
        <span class="date">
            {{ .Date.Format "2006/01/02" }}
        </span>
        <span>{{ .Title | markdownify }}.</span>
    </li>
    {{ end }}

If the above also doesn’t work for you, then please post the structure of your content folder and the contents of your project’s config.

1 Like

Unfortunately it does not work. I am going to edit the question and provide the structure of my content