IF Statement in RANGE

Hi,
i got this MD-File Structure

profiles:
  profile1:
    name: "Dr. Max Maier"
    office: "Head of Office"
    mail: "m.maier@mail.com"
    linkedin: ""
    imageSRC: "m.maier@mail.com"
    imageALT: "Max Maier"
  profile2:
    name: "Stefan Schmidt"
    office: "Communities & Cooperations"
    mail: "stefan.schmidt@mail.com"
    linkedin: "https://www.linkedin.com/in/123456789"
    imageSRC: "profile_picture.png"
    imageALT: "Stefan Schmidt"
  profile2:
    name: "Max Müller"
    office: "Communities & Cooperations"
    mail: "max.mueller@mail.com"
    linkedin: ""
    imageSRC: "profile_picture.png"
    imageALT: "Max Müller Picture"

and in the HTML File i try to get the infos like this

{{ if .Params.profiles }}
  {{ range .Params.profiles }}
  <div class="profiles">
    <img src="/images/about_us/{{ .imagesrc }}" alt="{{ .imagealt }}" class="profiles_image">
    <span class="profiles_name">{{ .name }}</span>
    <span class="profiles_office">{{ .office }}</span>
    <a href="mailto:{{ .mail }}" title="E-Mail to {{ .name }}"><img src="/images/icons/other/icon_yellow_mail.svg" alt="E-Mail icon" class="profiles_mail"></a>
    {{ if .linkedin }}
    <a href="{{ .linkedin }}" target="_blank" title="LinkedIn profile from {{ .name }}"><img src="/images/icons/other/icon_yellow_linkedin.svg" alt="LinkedIn icon" class="profiles_linkedin"></a>
    {{ end }}
  </div>
  {{ end }}
{{ end }}

The error:

ERROR 2019/10/15 08:40:08 Rebuild failed:

ERROR 2019/10/15 08:40:08 Process: loading templates: 
"/Users/daniellassak/Documents/GitLab/XXXX/themes/XXXX/layouts/page/single.html:19:1": parse 
failed: template: page/single.html:19: unexpected unrecognized character in action: U+00A0 in 
command

I know that i use the {{ if .linkedin }} wrong. But what is the correct format for this?

I don’t see any wrong with the snippet you posted, but the error message says “line 19” and you posted 13, so I guess it’s something we don’t see.

1 Like

Thats very strange. I deleted the {{ if .linkedin }} statement and typed it again… and now it works.

here the complete code:

{{ define "main" }}
{{ $baseURL := .Site.BaseURL }}

<h1 class="page_headline">{{ .Title }}</h1>

<section class="page">
  <div class="page_images">
    <img src="/images/{{ .Params.mainImageSRC }}" alt="" class="page_image">
  </div>

  <div class="page_content">
    {{ .Content }}

    {{ if .Params.profiles }}
      
      <div class="profiles">
        {{ range .Params.profiles }}
        <div class="profile">
          <img src="/images/about_us/{{ .imagesrc }}" alt="{{ .imagealt }}" class="profile_image">
          <span class="profile_name">{{ .name }}</span>
          <span class="profile_office">{{ .office }}</span>
          <a href="mailto:{{ .mail }}" title="E-Mail to {{ .name }}"><img src="/images/icons/other/icon_yellow_mail.svg" alt="E-Mail icon" class="profile_mail"></a>
          {{ if .linkedin }}
          <a href="{{ .linkedin }}" target="_blank" title="LinkedIn profile from {{ .name }}"><img src="/images/icons/other/icon_yellow_linkedin.svg" alt="LinkedIn icon" class="profile_linkedin"></a>
          {{ end }}
        </div>
        {{ end }}
      </div>
      
    {{ end }}
  </div>
  
</section>

{{ end }}

The char it complained about is an invisible character:

1 Like