# Making the web Svelter with SvelteKit ### Part 5 - Moving the PhotoAlbum index to a separate component [Back to part 4](part4_slides.html) --- ## PhotoAlbum Index component - Create /src/lib/components/PhotoAlbumIndex.svelte, and cut the relevant code form +page.js ```svelte []
Fotoalbum
makro
Norge 2020
``` --- ## And the CSS ```css [] ``` --- ## Include the component and add it to +page.js ```svelte [4]
``` --- ## Add album-data to +layout.js ```javascript[] export function load({ params }) { return { photos: [ //Same as before ], albums: [ { id: 'makro', image: 'IMGP4117.jpg', caption: 'makro', images: ['IMGP4117.jpg', 'background1.jpg', 'IMGP4642.jpg', 'IMGP6801.jpg', 'IMGP3329.jpg'] }, { id: 'norge2020', image: 'background1.jpg', caption: 'Norge 2020', images: ['IMGP4117.jpg', 'background1.jpg'] } ] }; } ``` --- ## Send data to the component in +page.svelte ```svelte[]
``` --- ## Get the album-data in PhotoAlbumIndex.svelte ```svelte [] ``` --- ## Use the album data in the markup ```svelte [4, 6, 7, 9, 11, 15-17, 19]
Fotoalbum
{#if albums}
{#each albums as album}
{album.caption}
{:else}
Ingen fotoalbum er lagt til
{/each}
{/if}
``` --- ## Onwards [part 6](part6_slides.html)