# Ad insertion Range - If Then Statement

**URL:** <https://discourse.gohugo.io/t/ad-insertion-range-if-then-statement/37678>\
**Category:** support\
**Created:** [March 15, 2022, 3:49pm UTC](https://discourse.gohugo.io/t/ad-insertion-range-if-then-statement/37678 "2022-03-15T15:49:59Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![dhugo2](https://avatars.discourse-cdn.com/v4/letter/d/e95f7d/32.png) [@dhugo2](https://discourse.gohugo.io/u/dhugo2)\
**Post date:** [March 15, 2022, 3:49pm UTC](https://discourse.gohugo.io/t/ad-insertion-range-if-then-statement/37678/1 "2022-03-15T15:49:59Z")

</div>

Good Day.  
I’m trying to add an advertising block in my list page where it ranges through my blog posts. Every 5 spot on the page (via pagination), I’d like to insert this. However, my IF-Then skips the 5th blog post – basically replaces the blog post.

Not sure if I should hack a blog post that has the ad code in it, or more likely get my if-then statement working. I’ve attached a schematic of the blog page below, and here’s my code snippet.

Suggestions? Hints? Tutorials? Thanks.

`/layouts/_default/list.html`

```auto
<div class="col-12">
  <div class="row">
    {{ $paginator := .Paginate (where site.RegularPages "Type" "in" site.Params.mainSections) }}
    {{ $.Scratch.Set "counter" 0 }}
    {{ range $paginator.Pages }}
    <div class="col-lg-4 col-md-4 col-sm-6">
      {{ $.Scratch.Set "counter" (add ($.Scratch.Get "counter") 1) }}
      {{ if eq ($.Scratch.Get "counter") 5 }}
        <!-- start ad placement -->
        <div style="border: 3px solid red;" id="pub-ad-placeholder"> </div>
        <!-- end ad placementt -->
      {{ else }}
         {{ .Render "article" }}
      {{ end }}
    </div>
    {{ end }}
  </div>

```

 ![CleanShot 2022-03-15 at 11.42.40@2x](https://canada1.discourse-cdn.com/flex036/uploads/gohugo/original/3X/c/4/c41c54d70170b940282adb8b1d5538138326e558.jpeg)

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [March 15, 2022, 3:59pm UTC](https://discourse.gohugo.io/t/ad-insertion-range-if-then-statement/37678/2 "2022-03-15T15:59:28Z")

</div>

[https://discourse.gohugo.io/t/how-to-insert-a-banner-inside-a-list-for-posts/33370/5](https://discourse.gohugo.io/t/how-to-insert-a-banner-inside-a-list-for-posts/33370/5)

---

<div class="post-metadata">

**Author:** ![dhugo2](https://avatars.discourse-cdn.com/v4/letter/d/e95f7d/32.png) [@dhugo2](https://discourse.gohugo.io/u/dhugo2)\
**Post date:** [March 15, 2022, 4:14pm UTC](https://discourse.gohugo.io/t/ad-insertion-range-if-then-statement/37678/3 "2022-03-15T16:14:40Z")

</div>

Hi.  
Thanks for the better search result, but that just adds the advertisement and squishes down the blog card (see attached). I’m hoping for more of an insertion/injection rather than a substitution (my original code) or the shared?/squished?/addition (referred link).

Attached is the result to my schematic. Thanks again.

 ![CleanShot 2022-03-15 at 12.09.48@2x](https://canada1.discourse-cdn.com/flex036/uploads/gohugo/original/3X/4/e/4e1cd14c253c7cfe590de36b3b828d5a07478129.jpeg)

---

<div class="post-metadata">

**Author:** ![dhugo2](https://avatars.discourse-cdn.com/v4/letter/d/e95f7d/32.png) [@dhugo2](https://discourse.gohugo.io/u/dhugo2)\
**Post date:** [March 15, 2022, 4:23pm UTC](https://discourse.gohugo.io/t/ad-insertion-range-if-then-statement/37678/4 "2022-03-15T16:23:27Z")

</div>

For clarification, this is the desired output/result.

 ![CleanShot 2022-03-15 at 12.22.31@2x](https://canada1.discourse-cdn.com/flex036/uploads/gohugo/original/3X/b/2/b23b65c33ba1657bc4c90c090b9fa2712d565895.jpeg)

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [March 15, 2022, 4:26pm UTC](https://discourse.gohugo.io/t/ad-insertion-range-if-then-statement/37678/5 "2022-03-15T16:26:56Z")

</div>

So that we don’t have to re-create your content and templates, can you share your project repository?

---

<div class="post-metadata">

**Author:** ![dhugo2](https://avatars.discourse-cdn.com/v4/letter/d/e95f7d/32.png) [@dhugo2](https://discourse.gohugo.io/u/dhugo2)\
**Post date:** [March 15, 2022, 4:39pm UTC](https://discourse.gohugo.io/t/ad-insertion-range-if-then-statement/37678/6 "2022-03-15T16:39:59Z")

</div>

Sorry, not public on bitbucket. Here’s the entire `list.htm`. Nothing special. It’s the Editor theme: [Editor - Gethugothemes](https://gethugothemes.com/products/editor/)

```auto
{{ define "main" }}

<!-- checking blog -->
{{ if or (eq .Section "post") (eq .Section "posts") (eq .Section "blog") (eq .Section "blogs") (eq .Section "news") }}
{{ partial "page-header.html" . }}

<div class="col-12">
  <div class="row">
    {{ $paginator := .Paginate (where site.RegularPages "Type" "in" site.Params.mainSections) }}
    {{ range $k, $v := $paginator.Pages }}
    <div class="col-lg-4 col-md-4 col-sm-6">
      {{ if and $k (modBool $k 5) }}
        <!-- ad placement start -->
        <div style="border: 3px solid red; height:200px;" id="ezoic-pub-ad-placeholder-118"> </div>
        <!-- End ad placement -->
      {{ end }}
         {{ .Render "article" }}
    </div>
    {{ end }}
  </div>

  <div class="row mb-4">
    <div class="col-12">
      {{"<!-- pagination -->" | safeHTML }}
      {{ $paginator := .Paginator }}
      <!-- Number of links either side of the current page. -->
      {{ $adjacent_links := 2 }}
      <!-- $max_links = ($adjacent_links * 2) + 1 -->
      {{ $max_links := (add (mul $adjacent_links 2) 1) }}
      <!-- $lower_limit = $adjacent_links + 1 -->
      {{ $lower_limit := (add $adjacent_links 1) }}
      <!-- $upper_limit = $paginator.TotalPages - $adjacent_links -->
      {{ $upper_limit := (sub $paginator.TotalPages $adjacent_links) }}
      <!-- If there's more than one page. -->
      {{ if gt $paginator.TotalPages 1 }}
      <nav class="mb-3">
        <ul class="pagination justify-content-center">
          <!-- Previous page. -->
          {{ if $paginator.HasPrev }}
          <li class="page-item"><a class="page-link arrow" href="{{ $paginator.Prev.URL }}" aria-label="Pagination Arrow">
            <i class="fas fa-angle-left"></i>
          </a></li>
          {{ end }}
          <!-- Page numbers. -->
          {{ range $paginator.Pagers }}
          {{ $.Scratch.Set "page_number_flag" false }}
          <!-- Advanced page numbers. -->
          {{ if gt $paginator.TotalPages $max_links }}
          <!-- Lower limit pages. -->
          <!-- If the user is on a page which is in the lower limit. -->
          {{ if le $paginator.PageNumber $lower_limit }}
          <!-- If the current loop page is less than max_links. -->
          {{ if le .PageNumber $max_links }}
          {{ $.Scratch.Set "page_number_flag" true }}
          {{ end }}
          <!-- Upper limit pages. -->
          <!-- If the user is on a page which is in the upper limit. -->
          {{ else if ge $paginator.PageNumber $upper_limit }}
          <!-- If the current loop page is greater than total pages minus $max_links -->
          {{ if gt .PageNumber (sub $paginator.TotalPages $max_links) }}
          {{ $.Scratch.Set "page_number_flag" true }}
          {{ end }}
          <!-- Middle pages. -->
          {{ else }}
          {{ if and ( ge .PageNumber (sub $paginator.PageNumber $adjacent_links) ) ( le .PageNumber (add $paginator.PageNumber $adjacent_links) ) }}
          {{ $.Scratch.Set "page_number_flag" true }}
          {{ end }}
          {{ end }}
          <!-- Simple page numbers. -->
          {{ else }}
          {{ $.Scratch.Set "page_number_flag" true }}
          {{ end }}
          <!-- Output page numbers. -->
          {{ if eq ($.Scratch.Get "page_number_flag") true }}
          <li class="page-item">
            <a href="{{ .URL }}" class="page-link{{ if eq . $paginator }} active {{ end }}">
              {{ .PageNumber }}
            </a>
          </li>
          {{ end }}
          {{ end }}
          <!-- Next page. -->
          {{ if $paginator.HasNext }}
          <li class="page-item"><a class="page-link arrow" href="{{ $paginator.Next.URL }}" aria-label="Pagination Arrow">
            <i class="fas fa-angle-right"></i>
          </a></li>
          {{ end }}
        </ul>
      </nav>
      {{ end }}
    </div>
  </div>

</div>

<!-- taxonomie page -->
{{ else if or (eq .Section "categories") (eq .Section "tags")}}
{{ partial "page-header.html" . }}

<div class="col-12">
  <div class="row">
    {{ range .Data.Pages }}
    <div class="col-lg-4 col-md-4 col-sm-6">
      {{ .Render "article" }}
    </div>
    {{ end }}
  </div>
</div>

<!-- regular page -->
{{ else }}

{{ partial "page-header.html" . }}
<section class="section">
  <div class="container">
    <div class="row">
      <div class="col-lg-10 mx-auto">
        <div class="content">
          {{.Content}}
        </div>
      </div>
    </div>
  </div>
</section>
{{ end }}
<!-- /regular page -->

{{ end }}

```

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [March 15, 2022, 4:40pm UTC](https://discourse.gohugo.io/t/ad-insertion-range-if-then-statement/37678/7 "2022-03-15T16:40:59Z")

</div>

See [https://discourse.gohugo.io/t/requesting-help/9132](https://discourse.gohugo.io/t/requesting-help/9132).

> If you can’t share your repository for whatever reason, consider creating a dummy repo that you _can_ share, which reproduces the problem you’re experiencing.

---

<div class="post-metadata">

**Author:** ![dhugo2](https://avatars.discourse-cdn.com/v4/letter/d/e95f7d/32.png) [@dhugo2](https://discourse.gohugo.io/u/dhugo2)\
**Post date:** [March 15, 2022, 4:56pm UTC](https://discourse.gohugo.io/t/ad-insertion-range-if-then-statement/37678/8 "2022-03-15T16:56:19Z")

</div>

Is there a range pointer (like a sql pointer) so that once I hit the ad insertion, I just put the pointer back one number so that it won’t skip Blog#5 as the range continues through it’s iteration?

Or would a Switch statement, which I think in Go is just a With statement be a plan of attack?

(can can get a vanilla repo up, but not till later.)
