我在 Hugo 主题中遇到此错误并修改了代码以使用 Hugo 文档中的一个简单示例,但仍然遇到错误。
unexpected "=" in operand
雨果版
Hugo Static Site Generator v0.40.1 linux/amd64 BuildDate: 2018-04-25T17:16:11Z
Go 版本
go version go1.12 linux/amd64
我直接从 GoHugo - Append 复制了这段代码示例。
错误
ERROR 2019/03/11 09:24:53 theme/partials/work.html : template: theme/partials/work.html:3: unexpected "=" in operand
简化模板
{{ partial "global-header.html" . }}
{{ $s := slice "a" "b" "c" }}
{{ $s = $s | append "d" "e" }}
<h1>David</h1>
我最初在 Hugo AirSpace 中得到错误work.html 部分第 13 行的模板。
采样线
{{ $categories = $categories | append .category }}
完整模板
{{ partial "global-header.html" . }}
<!-- Portfolio Start -->
<section id="portfolio-work">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="block">
<div class="portfolio-menu">
<ul>
{{ $categories := slice }}
{{ range .Site.Data.work.portfolio }}
{{ $categories = $categories | append .category }}
{{ end }}
<li class="filter" data-filter="all">Everything</li>
{{ range ( $categories | uniq ) }}
<li class="filter" data-filter=".{{ . }}">{{ . }}</li>
{{ end }}
</ul>
</div>
<div class="portfolio-contant">
<ul id="portfolio-contant-active">
{{ range .Site.Data.work.portfolio }}
<li class="mix {{ .category }}">
<a class="venobox" href="{{ $.Site.BaseURL }}{{ .image }}">
<img class="img-responsive" src="{{ $.Site.BaseURL }}{{ .image }}" />
<div class="overly">
<div class="position-center">
<i class="fa fa-search fz-20"></i>
<h2>{{ .name }}</h2>
<p>{{ .description }}</p>
</div>
</a>
</li>
{{ end }}
</ul>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- Clients Logo Section Start -->
<section id="clients-logo-section">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="block">
<div id="clients-logo" class="owl-carousel">
{{ range .Site.Data.work.clients }}
<div class="clients-logo-img">
<a href="{{ .url }}"><img src="{{ $.Site.BaseURL }}{{ .image }}" alt="Features"></a>
</div>
{{ end }}
</div>
</div>
</div>
</div>
</div>
</section>
最佳答案
我发现我的go版本老了,需要更新到1.11
我按照此处的说明进行操作
我有一个细微的变化,我使用 Go1.12 而不是 1.11
# From the docs
sudo tar -xvf go1.11.linux-amd64.tar.gz
# This is the latest version when I updated
sudo tar -xvf go1.12.linux-amd64.tar.gz
我还必须更新我的 hugo 版本。
任何时候我做了以下事情
sudo apt-get install hugo
我最终得到了第 40 版
我按照此处的说明转到了 version 53去的
关于go - 操作数中出现意外的 "=",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55093093/