This successfully loads posts from my posts folder and then iterates over each of them where at least one of these tags appears, excluding posts where there are no tags matching those in slice.
However, I haven’t been able to find a method where I write a slice of tags to exclude. I want to be able to exclude posts from this view based on if any of the posts tags matchs any one of the tags in the slice.
replacing intersect with "in" and "not in" both lead to no posts showing up. "!=" has the same effect.
How do I write a filter to exclude a post based on multiple tags?
If more context is needed, here is the repo, with the relevant work being done on the exclude-by-tag branch.
I would expect symdiff to return: [all, the, tags, that, you, have, plus, the, three, to, remove]
And now writing it down it doesn’t make any more sense to me
Let’s go another way with your task - break it into two parts
range through all posts
inside of the range check that none of the three tags is in the post
{{ $display_posts := (((.Site.GetPage "section" "/posts").Pages).ByDate.Reverse) }}
{{ range $post := $display_posts }}
{{ if ((not in .Params.tags "tag1") and (not in .Params.tags "tag2")) }}
something
{{ end }}
{{ end }}
Something like this… I am not sure if the syntax is correct.
Thanks for your continued help, I’m still not sure that’s right though. It’s appearing on my machine as if the second conditional doesn’t have an effect. For instance if I use:
{{ if ((not (in .Params.tags "question")) and (not (in .Params.tags "help")))}}
It will remove the post with the tag question but not the one tagged help. However, if I use the reverse:
{{ if ((not (in .Params.tags "help")) and (not (in .Params.tags "question")))}}
I remove all the posts with help, but the question reappears.
Is it possible that apply might be able to be fed a conditional check on a slice?
{{
if (
not ( <-- not
(in .Params.tags "question") <-- tag question
or <-- OR
(in .Params.tags "help") <-- tag help
)
)
}}
so:
{{ if (not ((in .Params.tags "question") or (in .Params.tags "help")))}}
It would really help if you could put a public repo online that we can use to play around. I am playing with Schroedingers cat here and though I read a day ago that they might have found a solution to have it being alive at all times I don’t have the mental capacity to confirm that
I did not use apply yet in my projects… so I got no idea about that without samples.
I am pretty sure Golang or Hugo has some kind of “string not in this array of strings” construct.
You know, the script kiddie solution would be the following:
{{ $display_posts := (((.Site.GetPage "section" "/posts").Pages).ByDate.Reverse) }}
{{ range $post := $display_posts }}
{{ if in .Params.tags "tag1" }}<!-- nah //-->
{{ else if in .Params.tags "tag2" }}<!-- nah either //-->
{{ else }}
THIS IS WHERE NEITHER TAG IS USED
{{ end }}
{{ end }}
I’ll be checking your repo now. Partial blindness on my behalf.
So that approach does work, but I’d really like to know if there is an alternative, so I’m going to leave this open for a bit to see if anyone else has an idea. If I don’t get a response tomorrow though, I’ll close this off with that solution