Displaying Fetched Data in a Each Loop

+page.svelte
<script>
	export let data;

	// Utility function to get the image URL
	function getImageUrl(id) {
		return `https://example.nl/assets/${id}?key=compression`;
	}

	function MakeUrlFriendly(input) {
		return input.replace(/[^a-zA-Z0-9]+/g, '-').toLowerCase();
	}
</script>

{#each data.data as post}

{/each}
<script>
	export let data;

	// Utility function to get the image URL
	function getImageUrl(id) {
		return `https://example.nl/assets/${id}?key=compression`;
	}

	function MakeUrlFriendly(input) {
		return input.replace(/[^a-zA-Z0-9]+/g, '-').toLowerCase();
	}
</script>

{#each data.data as post}
<div>{post.title}</div>
{/each}

Last updated