You'll build a site from several reusable components that utilise props for customisation.
It'll have the following features:
Command + Shift + A on MacOS or Ctrl + Shift + A on Windows)Ctrl + `npm run devNow you're ready to get coding!
Props are bits of extra information that you can send to a component. They can be anything, and we'll be using them firstly to send some text to display inside the component.
The first step is to make the Header component truly reusable, by making it take props for the title and subtitle, instead of them being hard-coded in.
script element at the top of your Header.svelte filetitle and subtitleexport keyword to the start of each variable declaration{title} and your subtitle with {subtitle}<script>
export let title
export let subtitle
</script>
<header class="hero">
<div class="hero-body">
<h1 class="title"> {title} </h1>
<h2 class="subtitle"> {subtitle} </h2>
</div>
</header>
Check your site in your page. Your header might look a bit strange. Undefined means that the variable has no value.
Let's give the variable a default value, so that it will display a bit more normally if it doesn't receive a prop.
<script>
export let title = 'Main heading'
export let subtitle = 'Secondary heading'
</script>
<header class="hero">
<div class="hero-body">
<h1 class="title"> {title} </h1>
<h2 class="subtitle"> {subtitle} </h2>
</div>
</header>
In the browser, you should now see your default values in the header. This is a good safety net, but not great for the user.
The last step is to update everywhere you use the Header component with attributes for each prop. Start with your home page.
title and subtitle props into your Header<Header title="Summer Gallery" subtitle="Images from summer" />
Update the Header on every page so that it sends the correct props for that particular page.
Your Footer is a fairly simple component, and may only take a couple of bits of information.
Update it with some props for author, date, and organisation. Use the same process as you did for the Header.
An component that's an image with a caption underneath will be very useful on a gallery website.
Image.svelte component in your lib folder<script>
export let src = ''
export let alt = ''
export let caption = ''
</script>
<figure>
<img src="{src}" alt="{alt}">
<figcaption> {caption} </figcaption>
</figure>
Image component with the appropriate props on your front page to display the images from your summerImage.svelte codeCongratulations, the fourth iteration of your web page is complete.
You've taken the code provided and customised it to create your unique site.
Along the way, you've learnt about these parts of coding.
(➕ means new things in this project)
Svelte
components for reusable blocks of code➕ props for making customisable components
Bulma
classes for using Bulma's pre-written CSSFrom here, you can take your page further, if you like, by adding images from your summer, links to your social media, YouTube channel, blog, or whatever you like.
In your coding career you will often need to look up how to do things. In this section are a couple of websites to help you find information online about how to do what you want to do.
Most frequently, a good Google search will be the best option. Remember to include the keywords "HTML" and the thing you want to do, so that Google will give you the best results (skip past the ads though!).