spf13/hugo — pull request #537 by swill (2014-10-02 14:31:00+00:00)
Title: Added 'in' and 'intersect' as template functions

This pull request adds support for 'in' and 'intersect' template functions. My motivation for developing this functionality was to be able to develop a 'similar posts' block which listed posts similar to ANY of the current pages tags.

Here is an example implementation in a `single.html` template:
```

Similar Posts

{{ $page_link := .Permalink }}
{{ $tags := .Params.tags }}
{{ range .Site.Recent }}
{{ $page := . }}
{{ $has_tags := intersect $tags .Params.tags | len | lt 0 }}
{{ if and $has_tags (ne $page_link $page.Permalink) }}

{{ $page.Title }}

{{ end }}
{{ end }}

```

Here is a simple set of tests to show how it works for different types: http://play.golang.org/p/thF-OCWclj