Expecting := in `{{ if .Lastmod }}`

I’m trying to make an Atom feed. Here’s what I have so far:

<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>blog orbits</title>
    <link href="{{ .Site.BaseURL }}/atom.xml" rel="self"/>
    <link href="{{ .Site.BaseURL }}/"/>
    <updated>{{ .Site.LastChange.Format "2006-01-02T15:04:05Z07:00" }}</updated>
    <id>{{ .Site.BaseURL }}/</id>
    <author>
        <name>frogorbits.com authorship junta</name>
    </author>
    {{ range where .Site.RegularPages "Section" "blog" }}
    <entry>
        <title>{{ .Title | htmlEscape }}</title>
        <link href="{{ .Permalink }}"/>
        <updated>
            {{- if .Lastmod -}}
                {{- .Lastmod.Format "2006-01-02T15:04:05Z07:00" -}}
            {{- else -}}
                {{- .Date.Format "2006-01-02T15:04:05Z07:00" -}}
            {{- end -}}
        </updated>
        <id>tag:frogorbits.com,
            {{- .Date.Format "2006" -}}
            :
            {{- .Permalink | split: "/" | last 1 -}}
        </id>
        <content type="html">{{ .Content | htmlEscape }}</content>
    </entry>
    {{ end }} 
</feed>

Thing is, I get two identical errors:

ERROR 2017/04/13 14:06:20 atom.xml : template: atom.xml:16: expected :=
ERROR 2017/04/13 14:06:20 atom.xml : template: atom.xml:16: expected :=

Line 16 is {{- if .Lastmod -}}. I have no idea why it’s expecting := there. Does anyone else here?

If I delete the if-else-end bits, the missing := error moves to line 17 (<id>tag:frogorbits.com,):

<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>blog orbits</title>
    <link href="{{ .Site.BaseURL }}/atom.xml" rel="self"/>
    <link href="{{ .Site.BaseURL }}/"/>
    <updated>{{ .Site.LastChange.Format "2006-01-02T15:04:05Z07:00" }}</updated>
    <id>{{ .Site.BaseURL }}/</id>
    <author>
        <name>frogorbits.com authorship junta</name>
    </author>
    {{ range where .Site.RegularPages "Section" "blog" }}
    <entry>
        <title>{{ .Title | htmlEscape }}</title>
        <link href="{{ .Permalink }}"/>
        <updated>
        </updated>
        <id>tag:frogorbits.com,
            {{- .Date.Format "2006" -}}
            :
            {{- .Permalink | split: "/" | last 1 -}}
        </id>
        <content type="html">{{ .Content | htmlEscape }}</content>
    </entry>
    {{ end }} 
</feed>

I’m currently using v. 0.20.7.

remove : after split

1 Like

…that did it. Thanks!

1 Like