Syntax for "contains a tag" versus equals a tag

HI all,

I’m modifying a theme that uses "!=" nil to check if a type (originally video) is in a post parameter to display it. I successfully changed this to use tags "=" "podcast" to pick up posts that have been tagged as a podcast (see code below). The problem I’m having is that posts with more than one tag do not get picked up by this. Is there a short way of writing the following so the query is whether the tags contain podcast rather than equal it?

          {{ range (where (where .Site.RegularPages "Type" "in" site.Params.mainSections) ".Params.tags" "=" "podcast") }}
            {{ partial "article.html" . }}
          {{ end }}

You could use the intersect operator.

{{ range (where (where .Site.RegularPages "Type" "in" site.Params.mainSections) ".Params.tags" "intersect" (slice "podcast") }}
  {{ partial "article.html" . }}
{{ end }}
1 Like

Thanks for the suggestion, unfortunately that doesn’t seem to pull in any podcast tagged posts though. Any other thoughts?

I suggest you post a link to the public repository for your project.

See https://discourse.gohugo.io/t/requesting-help/9132.

Let us see your code

Include a link to the source code repository of your project, because we really need the context of seeing your templates and partials to be able to help you. It is trivial to do a quick git clone on your repo, then run hugo server in your project, to help you out. On the other hand, recreating your code from screenshots, or sort of guessing at it, is not.

If you can’t share your repository for whatever reason, consider creating a dummy repo that you can share, which reproduces the problem you’re experiencing.

1 Like

Yeah, I know that’s more useful. It’s a purchased theme, so I’m not sure what the license deal is with putting it in a public repo. I decided to repurpose a different part of the theme that worked, since it’s based on tags. This uses a parameter in the config.toml and hooks the tags this way:

{{ if .Params.tags }}
                  <div class="article__tags">
                    {{ $tags_color := .Params.tags_color}}
                    {{ range (.GetTerms "tags") }}
                      <a href="{{ .Permalink }}" class="article__tag{{ if $tags_color }} tag-color-js{{ end }}" {{ if $tags_color }}data-accent="{{ $tags_color }}" style="color: {{ $tags_color }};"{{ end }}>{{ .LinkTitle }}</a>
                    {{ end }}
                  </div>
{{ end }}

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.