Ensure product images conditional rendering in astro file

Updated 'src/pages/products/[...slug].astro' to conditionally render product images only when they exist. Prevents potential errors or breaks in layout when there is an absence of either 'first' or 'second' blueprint images for a particular product.
This commit is contained in:
Emil Gulamov 2024-02-16 19:39:52 +04:00
parent 502aee8b33
commit c14e7fbdb3

View file

@ -168,21 +168,25 @@ const { product } = Astro.props;
<div
class="relative left-12 top-12 z-10 -ml-12 overflow-hidden rounded-xl shadow-lg md:left-12 md:top-16 lg:ml-0"
>
{product.data.blueprints.first &&
<Image
src={product.data.blueprints.first}
class="h-full w-full object-cover object-center"
alt="Blueprint Illustration"
format={"avif"}
/>
}
</div>
<div class="relative right-12 overflow-hidden rounded-xl shadow-xl">
{product.data.blueprints.second &&
<Image
src={product.data.blueprints.second}
class="h-full w-full object-cover object-center"
alt="Blueprint Illustration"
format={"avif"}
/>
}
</div>
</div>
</div>