Hello everyone and thank you for taking the tile to help me.
I need to do a condition according to the language of a website.
In the following partial i need tp display an aria label according to the language version of the website. The variables are correct, the data that is fetch in a json file is correct. If i dont make a lang condition it is working perfectly fine but as soon as i put the variables in the language condition they stay empty, i have tried everything. I have highlighted the concerned code to make it easy 😉
For context, the partial is called in a shortcode which works perfectly fine:
{{ $context := . }}
{{ $sortedTeachers := slice }}
{{ $cursusFilter := .Get "cursus"}}
{{ $language := $.Site.Language.Lang }}
{{ $teachers := index $.Site.Data.teachersList $language }}
{{ range sort $teachers "Nom" }}
{{ $sortedTeachers = $sortedTeachers | append . }}
{{ end }}
<section class="max-w-[90rem] items-center mx-auto grid md:grid-cols-2 lg:grid-cols-2 gap-3 mb-20">
{{ range $sortedTeachers }}
{{ partial "shared/teachers-list" (dict "context" $context "person" . "cursusFilter" $cursusFilter) }}
{{ end }}
</section>
And here is the partial:
{{ $language := $.Site.Language.Lang }}
{{ $name := index .person "Nom" }}
{{ $firstname := index .person "Prénom" }}
{{ $title := index .person "Civilité" }}
{{ $conseil := index .person "Conseil Scientifique" }}
{{ $domaine1 := index .person "Domaine1" }}
{{ $domaine2 := index .person "Domaine2" }}
{{ $cursus := index .person "Cursus" }}
{{ $cursusFilter := .cursusFilter }}
**{{ $skill1 := ""}}
{{ $skill2 := "" }}**
**{{ if eq $language "fr" }}
{{ $skill1 = $domaine1 }}
{{ $skill2 = $domaine2 }}
{{ else if eq $language "en" }}
{{ $skill1 = index .person "skill1" }}
{{ $skill2 = index .person "skill2" }}
{{ else if eq $language "ar" }}
{{ $skill1 = index .person "skillAr1" }}
{{ $skill2 = index .person "skillAr2" }}
{{ end }}**
{{ $skills := slice $skill1 $skill2 }}
{{ $customOrder := slice "Solutions métiers et souveraines" "Mathématiques" "Management des Systèmes d'Information" "Ingénierie logicielle" "Infrastructure" "Sciences de la Donnée" "Cybersécurité" "DevOps" "Développement Web et mobile" "Développement professionnel" "Bien-Être" }}
{{ if or (not (in $cursusFilter $cursusFilter)) (in $cursus $cursusFilter) }}
<div class="w-[85%] mx-auto relative teacher-card flex flex-col items-center my-6 px-6 {{ if eq $conseil "Oui" }}bg-violet text-white{{ end }}" id="{{ $firstname }}-{{ $name }}" {{ if (index .person "YouTube") }}data-video="btnVideoLabel"{{ end }} data-domaine1="{{ $domaine1 }}" data-domaine2="{{ $domaine2 }}">
{{ if eq $conseil "Oui" }}
<div class="m-3"><p class="absolute -top-0 right-0 w-auto text-xs text-center text-white m-3">Membre du Conseil Scientifique</p></div>
{{ end }}
<article class="w-[100%] mx-auto flex flex-col justify-center min-[800px]:justify-start lg:flex-row items-center md:items-start my-6 gap-6">
<div class="flex flex-col w-full md:min-w-[8rem]">
{{ if (index .person "Photo") }}
<div class="m-auto hexa-portrait-no-grayscale p-1 w-28">
<img src="/media/teacher/{{ index .person `Photo` }}" class="max-w-[8rem]" alt="{{ $name }}" loading="lazy" />
{{ else }}
<div class="w-11">
{{ end }}
</div>
<div class="relative flex flex-row justify-center W-20">
{{ range $customOrder }}
{{ $skill := . }}
{{ if in $skills $skill }}
{{ if eq $conseil "Non" }}
**<button class="infobulle w-[50%] h-[]" aria-label="{{ $skill }}"><img class="w-8 mx-auto" src="/media/icon/{{ $skill }}.webp"></button>
{{ else }}
<button class="infobulle w-[50%] h-[]" aria-label="{{ $skill }}"><img class="w-8 mx-auto" src="/media/icon/white/{{ $skill }}.webp"></button>**
{{ end }}
{{ end }}
{{ end }}
{{ if (index .person "YouTube") }}
<button popovertarget="{{ $name }}">
<img src="/media/icon/video-3.png" id="{{ $firstname }}" class="float-left w-8 m-4 object-contain cursor-pointer">
</button>
{{ end }}
</div>
</div>
<div>
<div class="flex justify-between">
{{ if (index .person "LinkedIn") }}
<a href={{ index .person "LinkedIn" }} class="external-link font-bold" target="_blank"> {{ $title }} {{ $firstname }} {{ $name }}</a>
{{ else }}
<p class="font-bold"> {{ $title }} {{ $firstname }} {{ $name }}</p>
{{ end }}
</div>
<p class="font-light">{{index .person "Campus"}}</p>
<div class="inline">
{{ if (index .person "Photo") }}
<div class="inline">
<p class="">{{index .person "Description" | markdownify}}</p>
</div>
{{ else }}
<div class="">
<p class="">{{index .person "Description" | markdownify}}</p>
</div>
{{ end }}
</div>
{{ if (index .person "YouTube") }}
<div popover id="{{ $name }}" class="w-auto lg:w-[70%] max-w-[50rem] h-[358px] overflow-y-hidden mx-auto bg-violet" data-youtube-src="https://www.youtube.com/embed/{{ index .person `YouTube` }}">
<iframe id="teacher-video" class="m-auto w-[100%] h-[350px] md:[100%]" src="https://www.youtube.com/embed/{{ index .person `YouTube` }}"
title="YouTube video player" allow="accelerometer; clipboard-write;
encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin"
allowfullscreen></iframe>
<button class="close-btn" popovertarget="{{ $name }}" popovertargetaction="hide">
<span id="{{ $name}}-{{ $firstname }}" popovertarget="{{ $name }}" class="absolute top-1 left-1 text-[#ffd200] font-bold cursor-pointer">X</span>
</button>
</div>
{{ end }}
</div>
</article>
</div>
{{ end }}
user25971064 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.