Breadcrumbs for Schema.org

I made a Schema.org compatible Breadcrumbs with such code.
However, the number of content = “{{$ i}}” does not increase.
please tell me.

{{ $i := 1 }}    
<div class="breadcrumbs">
      <ol itemscope itemtype="https://schema.org/BreadcrumbList">
        <li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem">
          <a itemprop="item" href="/">
            <span itemprop="name">HOME</span>
          </a>
          <meta itemprop="position" content="{{$i}}" />
        </li>
        {{ with .Params.categories }}
          {{ range . }}
            {{ $ := add $i 1 }}
            <li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem">
              <a itemprop="item" href="/categories/{{ . }}/">
                <span itemprop="name">{{ . }}</span>
              </a>
              <meta itemprop="position" content="{{$i}}" />
            </li>
          {{ end }}
        {{ end }}
        {{ with .Params.tags }}
          {{ range . }}
            {{ $i := add $i 1 }}
            <li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem">
              <a itemprop="item" href="/tags/{{ . }}/">
                <span itemprop="name">{{ . }}</span>
              </a>
              <meta itemprop="position" content="{{$i}}" />
            </li>
          {{ end }}
        {{ end }}

        {{ $i := add $i 1 }}
        <li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem">
          <a itemprop="item" href="{{.URL}}">
            <span itemprop="name">{{.Title}}</span>
          </a>
          <meta itemprop="position" content="{{$i}}" />
        </li>
      </ol>
    </div>

ああ

You are re-declaring the variable, instead of re-assigning it a value.

So instead of this

{{ $i := add $i 1 }}

Do this

{{ $i = add $i 1 }}
3 Likes

Thank you!!
I was able to improve!