Complete solution (100% reference)
index.html
- Main HTML pagescript.js
- JavaScript logicstyles.css
- Styling and layoutpackage.json
- Dependenciessetup.sh
- Setup scriptREADME.md
- Instructions (below)💡 Download the ZIP, extract it, and follow the instructions below to get started!
This is the complete solution (100% implementation) for Project One: My Biography from the W3 Server-Side Development & Authentication course.
This project demonstrates fundamental Svelte concepts including:
project-01-biography/
├── src/
│ ├── lib/ # Reusable components
│ │ ├── Header.svelte # Header component with title prop
│ │ ├── Section.svelte # Reusable section component with 4 props
│ │ └── Footer.svelte # Footer component with name prop
│ ├── routes/
│ │ └── +page.svelte # Main page with all components and data
│ └── app.html # HTML template with Bootstrap
├── package.json # Project dependencies
├── svelte.config.js # SvelteKit configuration
└── README.md # This file
Each component exports variables that become props:
<script>
export let title; // This becomes a prop
</script>
The Section.svelte
component is used three times with different data:
This demonstrates the power of reusable components in modern web development.
Instead of passing each prop individually:
<!-- ❌ Verbose way -->
<Section title={myInfo.title} item1={myInfo.item1} item2={myInfo.item2} item3={myInfo.item3} />
<!-- ✅ Better way with spread operator -->
<Section {...myInfo} />
The spread operator {...myInfo}
automatically passes all properties of the object as individual props.
Data is organized in objects that match the component props:
let myInfo = {
title: "Info",
item1: "Lee Kah Fai",
item2: 14,
item3: "SMJK (C) Chung Ling",
}
The footer uses data from the myInfo
object:
<Footer name={myInfo.item1} />
This ensures the name is consistent across the application.
cd "Paid Courses/W3 Server-Side Development & Authentication/Template Solution/project-01-biography"
npm install
Start the development server:
npm run dev
The application will be available at http://localhost:3000
To create a production build:
npm run build
Preview the production build:
npm run preview
src/lib/Header.svelte
)title
(string)<Header title="My Biography" />
src/lib/Section.svelte
)title
(string) - Section headingitem1
(string/number) - First itemitem2
(string/number) - Second itemitem3
(string/number) - Third item<Section {...dataObject} />
src/lib/Footer.svelte
)name
(string)<Footer name={myInfo.item1} />
src/routes/+page.svelte
)myInfo
, myHobby
, myPersonality
)The project uses Bootstrap 5 for styling, included via CDN in src/app.html
:
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"
rel="stylesheet"
/>
Students can enhance the styling by:
<style>
blocksTo personalize this biography:
Update personal information in src/routes/+page.svelte
:
myInfo
object with your detailsmyHobby
with your hobbiesmyPersonality
with your traitsAdd more sections by creating new data objects:
let mySkills = {
title: "Skills",
item1: "JavaScript",
item2: "Svelte",
item3: "CSS"
}
Enhance styling by adding Bootstrap classes or custom CSS
After studying this solution, students should understand:
The original project uses Svelte REPL (online editor) with App.svelte
. This solution adapts it to SvelteKit:
App.svelte
-> src/routes/+page.svelte
src/lib/
directory'./Header.svelte'
-> '../lib/Header.svelte'
)src/app.html
instead of component fileComponents provide several benefits:
Section.svelte
)The spread operator {...object}
is a JavaScript feature that:
Example:
// These two are equivalent:
<Section {...myInfo} />
<Section title="Info" item1="Lee Kah Fai" item2={14} item3="SMJK (C) Chung Ling" />
Components not displaying:
src/lib/
directoryProps not working:
export let propName;
{...object}
not {object}
Bootstrap styles not applying:
src/app.html
To enhance this project:
This project teaches foundational concepts used in:
This solution demonstrates:
If you have questions about this solution:
Course: W3 Server-Side Development & Authentication Project: 01 - My Biography Implementation: 100% Complete Solution Last Updated: October 2024