gothemesstatic-site-generation

golang - prevent two posts of a static site generator from appearing on the post list (about is one)


Using an older ssg I found a way to prevent something from showing up but I have the wrong syntax. Here is the area of concern. This is list.html template and shows all posts.

{{ define "body" }}
{{ if .IsFiltered }}
    </br><h2>Topics: {{ .FilteredTag.Name }}</h2>&nbsp;&nbsp;
{{ else }}
   </br><h2>All posts</h2>
{{ end }}
<div class ="list">
    {{ range .Posts }}
        <a href="{{ .ID }}.html">{{ .Title }} </a>&nbsp;&nbsp;{{ .Time.Format "2006-1-2" }}<br/>
    {{ end }}
</div>
{{ end }}

I need to add something similar to the following to prevent the "about" post from showing -


{{ if ne {{ .Title }} "about" }}

If I add it like this, I get an error -


{{ define "body" }}
{{ if .IsFiltered }}
    </br><h2>Topics: {{ .FilteredTag.Name }}</h2>&nbsp;&nbsp;
{{ else }}
   </br><h2>All posts</h2>
{{ end }}
<div class ="list">
    {{ range .Posts }}{{ if ne {{ .Title  }} "about" }}
        <a href="{{ .ID }}.html">{{ .Title }} </a>&nbsp;&nbsp;{{ .Time.Format "2006-1-2" }}<br/>
    {{ end }}
</div>
{{ end }}

Can you see what's wrong? My error states "unexpected {"


Solution

  • You need to write down your condition as follows:

    {{ if ne  .Title  "about" }}
    {{ end }}