Loops 雨果&x2013;如何根据计数器添加不同的类名
使用Hugo,我需要在前几篇文章中添加唯一的类名。如何做到这一点 我的代码显然不起作用Loops 雨果&x2013;如何根据计数器添加不同的类名,loops,templating,hugo,Loops,Templating,Hugo,使用Hugo,我需要在前几篇文章中添加唯一的类名。如何做到这一点 我的代码显然不起作用 // if the first post {{ if eq .Site.GetPage 1 }} {{ $classname := "class-one" }} // else the second post {{ elseif eq .Site.GetPage 2 }} {{ $classname := "class-two" }} // else the third post {{ els
// if the first post
{{ if eq .Site.GetPage 1 }}
{{ $classname := "class-one" }}
// else the second post
{{ elseif eq .Site.GetPage 2 }}
{{ $classname := "class-two" }}
// else the third post
{{ elseif eq .Site.GetPage 3 }}
{{ $classname := "class-three" }}
{{ else }}
{{ end }}
<li class="{{ $classname }}">
…
</li>
//如果第一篇文章
{{if eq.Site.GetPage 1}
{{$classname:=“一类”}
//否则第二个职位
{{elseif eq.Site.GetPage 2}
{{$classname:=“第二类”}
//否则第三个职位
{{elseif eq.Site.GetPage 3}
{{$classname:=“第三类”}
{{else}
{{end}
…
也许有更有效的方法,但这是可行的:
{{ $paginator := .Paginate (where .Data.Pages.ByDate.Reverse "Type" "post") }}
{{ range $index, $element := $paginator.Pages }}
{{ if (eq $index 0) }}
{{ $.Scratch.Set "classname" "class-one" }}
{{ else if (eq $index 1) }}
{{ $.Scratch.Set "classname" "class-two" }}
{{ else }}
{{ $.Scratch.Set "classname" "" }}
{{ end }}
<li class="{{ $.Scratch.Get "classname" | safeHTML }}">
…
</li>
{{ end }}
{{$paginator:=.Paginate(其中.Data.Pages.ByDate.Reverse“Type”“post”)}
{{range$index,$element:=$paginator.Pages}
{{if(eq$index 0)}
{{$.Scratch.Set“classname”“class one”}
{{else if(eq$index 1)}
{{$.Scratch.Set“classname”“class two”}
{{else}
{{$.Scratch.Set“classname”“”}
{{end}
…
{{end}