Home > Backend Development > Golang > golang - Prevent two posts from static site generator from appearing in posts list (about is one)

golang - Prevent two posts from static site generator from appearing in posts list (about is one)

王林
Release: 2024-02-09 17:24:08
forward
647 people have browsed it

golang - 防止静态站点生成器的两个帖子出现在帖子列表中(关于是一个)

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.

Question content

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 }}
Copy after login

I need to add something similar to the following to prevent "About" posts from showing up -

{{ if ne {{ .Title }} "about" }}
Copy after login

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 }}
Copy after login

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

Solution

You need to write down your situation as follows:

{{ if ne  .Title  "about" }}
{{ end }}
Copy after login

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!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template