Need help with array iteration in Html/Template

I’m trying to do for an range and access the content of more than one array to build a div in html.
I’m passing the data in separated arrays:

But it’s not working, and I’m not finding any working example to improve it// test it.

Creating the data:

		for _, relatedPost := range relatedPosts {
			RelatedPostsTitles = append(RelatedPostsTitles, relatedPost.Title)
			RelatedPostsImages = append(RelatedPostsImages, relatedPost.Image)
			RelatedPostsSynopsies = append(RelatedPostsSynopsies, relatedPost.Synopsis)
			RelatedPostsSlugs = append(RelatedPostsSlugs, relatedPost.Slug)
		}

		fmt.Printf("\n%+v\n", RelatedPostsSlugs)
		// blog post
		return c.Status(http.StatusOK).Render("post.html", fiber.Map{
			"Title":           post.Title + " - " + postID + " - afa7789 ",
			"PostID":          postID,
			"PostDate":        post.CreatedAt.Format("01-02-2006"),
			"PostImage":       post.Image,
			"PostTitle":       post.Title,
			"PostContent":     template.HTML(string(markdown.ToHTML([]byte(post.Content), nil, nil))),
			"RPostsID":        RelatedPostsIDs,
			"RpostsSlugs":     RelatedPostsSlugs,
			"RPostsImages":    RelatedPostsImages,
			"RPostsTitles":    RelatedPostsTitles,
			"RPostsSynopsies": RelatedPostsSynopsies,
		})

this is the print [seven-deadly-sins tulio-is-fren]

Then I have my html with this snippet:

       </style>
        {{if .RPostsID}}

            {{ $images := .RPostsImages }}
            {{ $synp := .RPostsSynopsis }}
            {{ $titles := .RPostsTitles }}
            {{ $slugs := .RPostsSlugs }}

            {{range $i, $id := .RPostsID}}
                <div>
                    <p>bolinha?</p>
                    <a href="/blog/{{$id}}-{{index $slugs $i}}">
                        <p>{{index $titles  $i}}</p>
                        <p>{{index $synp  $i}}</p>
                    </a>
                    <hr class="horizontal_line_class" />
                <div>
            {{end}}
        {{end}}
    </section>

but I keep getting this error :
template: post.html:79:45: executing "post.html" at <index $slugs $i>: error calling index: index of untyped nil

Is lowercase in your code and uppercased in your template:

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