Questions for use range

hi i have a question

hi i created a authors taxonomy where i add name and pictures in my blog with cards design on for listing all articles. If i have 2 authors i add two name’s authors but picture of first author only.
i search one best solution . because i call same range after for others informations. i wish call this range only one upon time for best performance or best practice :wink:
Could you help me please ?
i use this code pour create this situation

{{ define “main” }}

{{ range .Pages }}

<div>
    <img src="{{with .Params.featured_image}}{{.}}{{else}}{{ .Site.Params.featured_image }}{{end}}" alt=""
        class="object-fill w-full h-40">
</div>
<div class=" m-2 text-justify text-sm ">

    <div class="flex flex-wrap items-center -mt-8 pb-3 ">
        <img class="block h-8 w-8 rounded-full bg-white mt-1 mr-2 ml-3 border-2 border-white "
            src='{{ range first 1 .Params.authors }}
            {{with $.Site.GetPage "taxonomyTerm" (printf "authors/%s" (urlize .)) }}{{ with   .Params.photo }}{{ . }}{{ else }}{{ .Site.Params.authorimage }}{{ end }}{{ end }}{{ end }}'
            alt="image de l'auteur">
        {{ range .Params.authors }}
        {{with $.Site.GetPage "taxonomyTerm" (printf "authors/%s" (urlize .)) }}
        <a href='{{ .Permalink }}'><span
                class="block text-lg font-bold text-white">{{ with .Params.name }}{{ . }}{{else}}{{ .Site.Params.author }}{{end}}{{ end }}{{ end }}</span></a>

    </div>
    <div class=" ">
        <p class=" text-right -mt-4 text-xs"> <i class=" mr-1 far fa-calendar-alt"></i>

            <!-- date en Fr via data/mois.yaml merci https://www.christopheducamp.com/ ;) -->
            <time class="post-date dt-published"
                datetime='{{ .Date.Format "2006-01-02T15:04:05Z07:00" | safeHTML }}'>{{ .Date.Day }}
                {{ index $.Site.Data.mois (printf "%d" .Date.Month) }} {{ .Date.Year }}</time> </p>

        <p class=" text-right  text-xs"> <i class=" mr-1 fas fa-clock"></i>
            {{.ReadingTime }} minutes
        </p>
        <h2 class=" font-bold mb-1 text-center"> <a href="{{ .Permalink }}">{{ .Title }}</a> </h2>


        <p class=" h-32 md:h-40 text-xs p-3"> {{ with .Params.description }}
            {{ . }}
            {{ else }}
            {{ .Summary }}
            {{ end }}
        </p>

    </div>

</div>
<a href="{{ .Permalink }}">
    <div class=" absolute bottom-0 w-full py-2   text-center bg-blue-500 hover:bg-blue-900 text-white  ">
        Lire
    </div>
</a>
{{ end }} {{ end }}

It is not clear what your question is. Please share a repo and explain the issue you are having in more detail.

ok…
hi
if i have two or many authors for one post :

i enter one the range one uponce
img class="block h-8 w-8 rounded-full bg-white mt-1 mr-2 ml-3 border-2 border-white "
src=’{{ range first 1 .Params.authors }}
{{with $.Site.GetPage “taxonomyTerm” (printf “authors/%s” (urlize .)) }}{{ with .Params.photo }}{{ . }}{{ else }}{{ .Site.Params.authorimage }}{{ end }}{{ end }}{{ end }}’
alt=“image de l’auteur”>

and second uponce for :
{{ range .Params.authors }}
{{with $.Site.GetPage “taxonomyTerm” (printf “authors/%s” (urlize .)) }}
{{ with .Params.name }}{{ . }}{{else}}{{ .Site.Params.author }}{{end}}{{ end }}{{ end }}

i search solution for call one only uponce this range for good power :slight_smile:

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.