Range (where .Site.Pages is "A", BUT NOT "B")

Hello,

I’m trying to display only the blogs where my Params.type is “news”, and not “notices”.

I’m displaying news like this:

{{ range first 2 (where .Site.Pages ".Params.type" "news") }}

and I thought of this:

{{ range first 2 (where .Site.Pages ".Params.type" "news") }}
{{ if ne .Params.categories "notices" }}

and it works! Only that instead of displaying one newspost, then noticing the next newspost in line is, instead, a “notice”, and move to the next post in line (which is a newspost and should be displayed), it displays the first post (news post), then a blank space.

Like so:
What I have:

  • NEWS POST
  • NOTICE POST
  • NEWS POST

desired effect:

  • NEWS POST
  • NEWS POST

what happens:

  • NEWS POST

See that blank there? :frowning:

That’s probably because you used

{{ range first 2 ...

So, if you have

1 News
2 Notice
3 News

first 2 finishes running at 2 Notice and never reaches 3 News.

1 Like

;-D Yes, but if I do first 3 then it shows 3 instead of 2 when I only want 2 posts shown all the time.

If I do first 3, it shows 2, in THIS particular case, but if my next 3 posts are all News then it shows 3 posts on the page ;-( (only want/need 2 at all times)

Isn’t there a way to do:

(pseudo-code)

range first 2 ( where .Site.Pages ".Params.type" "news" AND NOT ".Params.categories" "notices")

Or a least to save the results into an array or something?

You could try…
{{ range first 2 (where (where .Site.Pages ".Params.type" "news") ".Params.category" "!=" "notice" ) }}

1 Like

That did the trick, thanks pointyfar; I honestly had no idea no idea “(where (where” was a thing was a thing.

Thanks thanks.

Javier Javier.

1 Like