#Pass and Image path in a map
3 messages · Page 1 of 1 (latest)
To pass the image reference in your map function for the solution_links, you need to modify your code slightly. In Astro, when working with local images, you need to import them and use the imported object directly. Here's how you can adjust your code:
---
import { Image } from 'astro:assets';
import anpc_sal from "../../assets/anpc-sal.webp";
import anpc_sol from "../../assets/anpc-sol.webp";
const links = [
// ... other links ...
{
href: "<https://anpc.ro/ce-este-sal/",>
text: "Solutionarea alternativa a litigiilor.",
icon: anpc_sal,
},
{
href: "<https://ec.europa.eu/consumers/odr/",>
text: "Solutionarea online a litigiilor.",
icon: anpc_sol,
}
];
// ... rest of your code ...
---
<footer>
<div class="bg-base-content">
<div class="container">
<div class="mb-4 flex gap-8 max-md:flex-col">
{
solution_links.map(({ href, text, icon }) => (
<a
href={href}
target="_blank"
>
<Image src={icon} alt={text} />
</a>
))
}
</div>
</div>
</div>
</footer>
In this modified code:
- We import the
Imagecomponent fromastro:assetsat the top of the file. - The
iconproperty in yourlinksarray now directly references the imported image objects (anpc_salandanpc_sol). - In the JSX, we use the
Imagecomponent instead of animgtag, and pass theicondirectly as thesrcprop.
This approach works because when you import an image in Astro, it returns an object that can be used directly with the Image component as explained in the Astro documentation (https://docs.astro.build/en/guides/images/#images-in-astro-files).