Selecting a post by output format

Suppose I have a post that declares this in its metadata:

- special

as well as an accompanying format definition in my config:

    name: special

How can I use a (where ... "OutputFormats" ???) to select only posts which will be built in a format named special? Every obvious variation of where I tried to so far results in selecting nothing: OutputFormats is not a list of string names of output formats. I had to resort to introducing a cascading flag to duplicate this information, but I’d rather take it out if I can.

Something like this?

{ range where .Site.Pages "Params.outputs" "special" }}
1 Like

Nope, that selects nothing.

There are two examples in the Custom Output Formats doc that I start with, and modify as needed:

{{ range .AlternativeOutputFormats -}}
<link rel="{{ .Rel }}" type="{{ .MediaType.Type }}" href="{{ .Permalink | safeURL }}">
{{ end -}}
{{ .RelPermalink }} > /that-page/
{{ with  .OutputFormats.Get "json" -}}
{{ .RelPermalink }} > /that-page/index.json
{{- end }}

I use the range over AlternativeOutputFormats (first sample code above) as the first test that my custom output is working. :slight_smile:

And how, exactly, would you translate that to selecting posts from a complete list of posts by output format? Because you’re ranging across possible formats, not posts, here.

{{ range $p := site.RegularPages }}
  {{ with .OutputFormats.Get "special" }}
    <a href="{{ $p.RelPermalink }}">{{ $p.LinkTitle }}</a>
  {{ end }}
{{ end }}

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