# collections.Intersect
> 返回两个给定切片中的公共元素，顺序与第一个切片一致。
- 官方英文原文：https://gohugo.io/functions/collections/intersect/
- 本页规范地址：https://hugozh.cn/functions/collections/intersect/
- 最近更新：2026-10-02
- 最后提交：912b1d3 chore(site): 添加 static/CNAME（hugozh.cn），供 GitHub Pages 等平台绑定自定义域名
- 签名：collections.Intersect SLICE1 SLICE2
- 返回类型：[]any
- 站点：Hugo 中文文档（https://hugozh.cn/）· 社区维护的非官方中文翻译，如有出入以官方英文原文为准

---
一个有用的例子是把它与 where 组合起来，当作 `AND` 过滤器使用：

```go-html-template
{{ $pages := where .Site.RegularPages "Type" "not in" (slice "page" "about") }}
{{ $pages := $pages | union (where .Site.RegularPages "Params.pinned" true) }}
{{ $pages := $pages | intersect (where .Site.RegularPages "Params.images" "!=" nil) }}
```

上面的代码会取出类型不是 `page` 或 `about` 的普通页面，除非它们被 pin 了。最后，我们排除掉所有未在 Page 参数中设置 `images` 的页面。

`OR` 请参见 [union][]。

[union]: /functions/collections/union/

