Rick Cogley's Tech Logr

Short Technical Laser Bursts %%

RC Logr 20190219 201247

Tuesday, 19 Feb, 2019

Got asked by a client to add a second URL to a block on a seminar page, but they wanted to add a counter for seminars with two URLs, so the page would show “seminar URL 01” and “seminar URL 02”. I’m pulling json from a db, then using Hugo to build the site, ranging over the json to build the seminar page. I added a field in the db to contain the second URL, and some conditional code to display the counter. The challenge was to add the counter only for seminars with two URLs, but not for those with one. For the first URL I used a with clause, and added the counter only in the case that the second URL was set.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
...
{{ with (index . "セミナー URL") }}
  <div class="flex flex-column flex-row-ns">
   <div class="dtc v-top w-100 w-30-ns">
     <p class="b lh-copy mv0">セミナー URL{{ with ($.Scratch.Get "surltext2") }}(01){{ end }}</p>
    </div>
    <div class="dtc v-top pl3 w-100 w-70-ns">
      <p class="lh-copy mv0">
      <span class="dn-s"><a href="{{ . }}" target="_blank" class="no-underline purple hover-gold">{{ $.Scratch.Get "surltext" }}</a></span>
      <span class="dn-ns"><a href="{{ . }}" target="_blank" class="no-underline purple hover-gold">リンク</a></span>
      </p><br/>
    </div>
  </div>
{{ end }}
...

RC Logr 20190219 201247 - Got asked by a client to add a … Rick Cogley
Back to Home Tweet Link