Are these expressions the same?

Hey, are these expressions the same? Are there any differences to be aware of? Is either a Hugoism?

Example 1

    {{ $pages := $.Site.RegularPages }}
    {{ range $pages }}
        {{ $page := .}}
        {{ with (.Resources.Match "special*") }}
            {{ . }}
            {{ $page.RelPermalink }}
        {{ end }}
    {{ end }}

Example 2

    {{ $pages := $.Site.RegularPages }}
    {{ range $pages }}
        {{ if ne (.Resources.Match "special*") nil }}
            {{ .Resources.Match "special*" }}
            {{ .RelPermalink }}
        {{ end }}
    {{ end }}

I don’t understand the example, but this is how I would write it:

{{ range $p := site.RegularPages }}
  {{ with .Resources.Match "special*" }}
    {{ . }}
    {{ $p.RelPermalink }}
  {{ end }}
{{ end }}

I am creating a secondary nav from only some resources with a name prefix. I am specificaly asking about whether there is a difference to using an if conditional within a range OR using a with within the range.

with rebinds the context, as shown in both of our examples.

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