php editor Xiaoxin brought an article about golang to discuss how to prevent two posts in the static site generator from appearing repeatedly in the post list. Static site generator is a common website development tool, but sometimes posts are displayed repeatedly, which is not ideal for the user experience. This article will introduce methods to solve this problem and help developers improve the quality and user experience of their websites.
Using an older ssg, I found a way to prevent some content from showing up, but I got the syntax wrong. This is an area of concern. This is the list.html template and displays all posts.
{{ define "body" }} {{ if .IsFiltered }} </br><h2>Topics: {{ .FilteredTag.Name }}</h2> {{ else }} </br><h2>All posts</h2> {{ end }} <div class ="list"> {{ range .Posts }} <a href="{{ .ID }}.html">{{ .Title }} </a> {{ .Time.Format "2006-1-2" }}<br/> {{ end }} </div> {{ end }}
I need to add something similar to the following to prevent "About" posts from showing up -
{{ if ne {{ .Title }} "about" }}
If I add it like this I get the error -
{{ define "body" }} {{ if .IsFiltered }} </br><h2>Topics: {{ .FilteredTag.Name }}</h2> {{ else }} </br><h2>All posts</h2> {{ end }} <div class ="list"> {{ range .Posts }}{{ if ne {{ .Title }} "about" }} <a href="{{ .ID }}.html">{{ .Title }} </a> {{ .Time.Format "2006-1-2" }}<br/> {{ end }} </div> {{ end }}
Can you see what's wrong? My error states "Unexpected{"
You need to write down your situation as follows:
{{ if ne .Title "about" }} {{ end }}
The above is the detailed content of golang - Prevent two posts from static site generator from appearing in posts list (about is one). For more information, please follow other related articles on the PHP Chinese website!