This tutorial will teach you to build the frontend and backend of a school website using the Strapi API, HTML, CSS, and Vanilla Javascript. There won't be any framework in it. Considering the target population, the design will be straightforward and uncluttered. I'll be talking about a school website I created using backend services in this blog post. I've previously worked with local JSON data, and it's challenging to update and delete the material.
Strapi is a free and open-source Headless CMS that allows for quick and easy API design and content management. You will learn how to use vanilla JavaScript and Strapi CMS to create a school website.
Make sure your computer has the following installed before we start.
The REST API, often known as a RESTful API, divides a transaction into several tiny components. Every module deals with a fundamental aspect of the transaction. Although this modularity offers developers a great deal of freedom, it might be difficult for developers to create a REST API from scratch. Several businesses already provide models for developers to use; the most well-liked models are those offered by Strapi. Commands are used by a RESTful API to access resources. A resource representation is the status of a resource at any particular timestamp.
The REST API in Strapi enables access to the various content types via API endpoints. When a content type is created using Strapi, API endpoints are automatically created. When making a query to an API endpoint, API parameters can be used to filter the results. There are no relations, media fields, components, or dynamic zones by default when using the REST API. Fill up particular fields by using the populate argument.
When you are familiar with the tool you want to use, the official documentation is the best place to start. When working with something new, repress the urge to jump right in and read the manual instead. You will also make time and effort savings as your skills as a developer advance. You can learn about many different subjects by reading. You will be better able to understand the next topic by knowing more about one area of software development.
Endeavor to go through each example in a Getting Started lesson. Before moving on, be sure you understand the foundational ideas of a new language or system.
Finally, familiarize yourself with the code. Reading the documentation alone probably won't be enough to understand what the program is doing. A little glance at the source code can have a significant impact. Utilize each and every piece of code by copying it, reading it, and determining what it does. Try out the code yourself to see how it works. Start it over again. Break it. then choose a resolution.
Use this GitHub link to clone the school's website. The final step is to add the common JavaScript files in order to access the data from Strapi. To save the school website, decide where to put it on your computer.
git clone https://github.com/Dmuasya/SchoolWebsiteStrapi.git
cd SchoolWebsiteStrapi
npx create-strapi-app backend --quickstart
This results in the creation of a new Strapi app in a backend folder. The —quickstart
flag instructs Strapi to use SQLite as its preferred database. When given the option to utilize a different database, omit the flag and select that database instead.
The length of time it takes to complete the installation will depend on how quickly your network is.
strapi develop
You should see your browser launch at http://localhost:1337/admin/auth/register. If not, manually launch your preferred browser. It will display a sign-up form similar to the one below.
On this page, your APIs are listed in the upper-left corner. It should only contain the Users API for the time being.
The fields for this collection can be chosen on a new screen that should appear after clicking "Continue." From the list, select the "Text" field, then give it a name.
When creating a new grade, make sure this information is compulsory by selecting "Advanced options" and checking the "Required field" box.
You’re done creating the grades endpoint.
HTML is a powerful tool that gives your code superpowers if you want to utilize it. The built-in behaviors in HTML allow you to reduce the amount of explicit code you need to utilize. By organizing your papers so that they work well and look good, you may make your content accessible to more people and software.
The project demystifies fundamental HTML tags and properties while instructing you on how to write semantic, meaningful HTML. It helps you ensure that your pages (including elements like navigation) are properly arranged and sectioned while also showing you how to use the language's unique features for presenting quotes, figures, dates, and timings.
By design, HTML is a tolerant language that permits the execution of even subpar code. Our school website won't render without components like , ,
, and . Certain browsers won't correctly display pages without these auxiliary elements.1<!DOCTYPE html>
2<html lang="en">
3<head>
4 <meta charset="UTF-8">
5 <meta name="viewport" content="width=device-width, initial-scale=1.0">
6 <title>School Website - Strapi CMS</title>
7 <link rel="stylesheet" href="css/minified/style.min.css">
8 <script
9 src="https://kit.fontawesome.com/fc31dedf63.js"
10 crossorigin="anonymous"
11 ></script>
12</head>
13<body>
14
15 <!-- Modal on page load -->
16 <div class="modal" id="modal-one" aria-hidden="true">
17 <div class="modal-dialog">
18 <div class="modal-header">
19 <h2>Namaste !</h2>
20<a href="#modal-one" class="btn-close" aria-hidden="true">×</a>
21
22 </div>
23 <div class="modal-body">
24 <p>This is the Moi Forces Academy Website but it's <br />
By following the few straightforward guidelines below, we can maintain our code well-organized.
When we decide on a technique that we like. It must be adhered to strictly, applied everywhere, and kept separate.
1 <!-- acheivements section -->
2
3 <section class="achieve">
4
5 <!-- achieve container -->
6 <div class="achieve__container">
7 <h1 class="achieve__h1"></h1>
8 <div class="achieve__section">
9 <div class="achieve__sectionList">
10 <img class="achieve__imgIcon" src="./img/ach1.png" alt="achieveIcon" />
11 <h3 class="achieve__h3"></h3>
12 <p class="achieve__p"></p>
13 </div>
14
15 <div class="achieve__sectionList">
16 <img class="achieve__imgIcon1" src="./img/ach2.png" alt="achieveIcon" />
17 <h3 class="achieve__h31"></h3>
18 <p class="achieve__p1"></p>
19 </div>
20
21 <div class="achieve__sectionList">
22 <img class="achieve__imgIcon" src="./img/ach3.png" alt="achieveIcon" />
23 <h3 class="achieve__h32"></h3>
24 <p class="achieve__p2"></p>
25 </div>
26
27 <div class="achieve__sectionList">
28 <img class="achieve__imgIcon" src="./img/ach4.png" alt="achieveIcon" />
29 <h3 class="achieve__h33"></h3>
30 <p class="achieve__p3"></p>
31 </div>
32
33 </div>
34 </div>
35 <!-- End achieve container -->
36
37 </section>
38
39 <!-- End acheivements section -->
Last but not least, although inline styling first seems to be easier, it actually requires more upkeep and adds to the line of code. If we use an external stylesheet, we can choose to reuse our code. A single external stylesheet can also be used to style all of our pages.
The Document Object Model (DOM) represents the objects that make up the structure and content of a web document (DOM) as data. It illustrates how to use APIs to construct websites and web applications as well as how an HTML document is represented in memory.
The good news is that contemporary browsers have begun to provide module capability in native implementations. This can only be a good thing as it enables browsers to load modules more rapidly and effectively than they would be able to if they had to use a library and carry out all of the additional client-side processing and round trips.
1import { localhost } from "./../../adminUrl.js";
2
3export const Blog = async () => {
4
5 try {
6
7 const url = `${localhost}/eventsblogs?_sort=id:DESC`;
8 const ftch = await fetch(url);
9 const data = await ftch.json();
10 const result = data;
11 //console.log(result[0].content);
12
13
14 for (let i in result) {
15
16 const container = document.querySelector(".blog__container");
17
18 const dv = document.createElement("div");
19 dv.classList = "blog__single";
20
21 const img = document.createElement("img");
22 img.classList = "blog__img"
23 img.src= `${result[i].thumbnailimg.url}`;
24
25
26 const heading = document.createElement("h1");
27 heading.classList = "blog__heading";
28 heading.textContent = `${result[i].title}`;
29
30 const desc = document.createElement("p");
31 desc.classList =" description";
32 desc.textContent = `${result[i].description}`;
33
34 const date = document.createElement("p");
35 date.classList ="date";
36 date.textContent = `${result[i].date}`;
37
38 const hrf = document.createElement("a");
39 hrf.classList = "below";
40 hrf.textContent = "Read More Below:";
41
42
43 const readmore = document.createElement("div");
44 readmore.classList = "readmore";
45 readmore.textContent = `${result[i].content}`;
46
47
48 const hr = document.createElement("hr");
49
50 dv.appendChild(img);
51 dv.appendChild(heading);
52 dv.appendChild(desc);
53 dv.appendChild(date);
54 dv.appendChild(hrf);
55 dv.appendChild(readmore);
56 dv.appendChild(hr);
57
58
59 container.appendChild(dv);
60
61 }
62
63 }
64
65 catch(error) {
66 console.log("failed", error);
67 }
68 }
The import and export declarations are necessary for the use of native JavaScript modules. Imagine yourself in a circumstance where you must reuse some JavaScript code. ES6's concept of modules comes to the rescue.
Each module corresponds to a corpus of JavaScript code. Modules contain both functions and variables. A module is nothing more than a segment of JavaScript code that has been written in a file. A module's internal variables and functions are not accessible by default. By exporting them from a module, variables and functions can be accessed from other files. In ES6, modules can only function in strict mode. This implies that any variables or functions defined in a module won't be globally accessible.
Sass is the world's most advanced, dependable, and effective CSS extension language. Thanks to the integration of internal Sass capabilities into the module system, we now have complete control over the global namespace. Before using, the built-in modules math, color, text, list, map, selector, and meta must be manually imported into a file.
1.blog {
2 margin-top: 7rem;
3 margin-left: 7rem;
4 margin-right: 7rem;
5 margin-bottom: 3rem;
6}
7
8.blog__h1 {
9 // text-align: center;
10 font-size: 2.3rem;
11 margin-bottom: 5rem;
12}
13
14.blog__img {
15 object-fit: cover;
16 width: 40%;
17 height: 230px;
18 border-radius: 21px;
19 margin-bottom: 2.5rem;
20}
21
22.blog__heading {
23 margin-bottom: 1rem;
24}
25
26.description {
27 max-width: 85ch;
28 margin-bottom: 0.5rem;
29}
30
31.date {
32 margin-bottom: 0.4rem;
33 font-size: 1.3rem;
34 color: blueviolet;
35}
36.below {
37 // margin-bottom: 0.6rem;
38 background-color: burlywood;
39 color: #fff;
40 padding: 0.2rem;
41 font-size: 1rem;
42 margin-top: 2rem;
43}
44
45.readmore {
46 margin-top: 2rem;
47 max-width: 97ch;
48 color: #3a3838;
49 word-spacing: 0.2rem;
50 letter-spacing: 0.1rem;
51 line-height: 1.7;
52}
53
54.blog__single {
55 margin-top: 4rem;
56}
57
58@media all and (max-width: 768px) {
59 .blog {
60
61 margin-left: 1rem;
62 margin-right: 1rem;
63 margin-bottom: 3rem;
64 }
65
66 .blog__img {
67
68 width: 100%;
69
70 }
71
72}
In computer science, there are just two difficult issues: invalidating caches and naming things. It is common knowledge that the use of a proper style guide can speed up development, debugging, and the integration of new features into legacy code. Unfortunately, the majority of CSS codebases are occasionally created with no organization or naming rules. Long term, this results in a CSS codebase that is unmaintainable.
The name Block Element Modifier is abbreviated as BEM. It guarantees that everyone involved in the creation of a website uses the same codebase and same language. You can become ready for changes to the website's appearance by using correct naming.
Below is an image the design of the school website.
You downloaded the Strapi app and created an API throughout this tutorial. Then you added sample grades to display and made a few routes of the API accessible. Last but not least, you copied a basic JavaScript School website and added scripts to fetch and show data from the Strapi app. Consider listing grades in the site and making the tags clickable if you want to give the app extra capabilities. I'll close by challenging you to take it a step further by including more fields in the API and turning on the fallback option so you can test how it functions when new data is added to the backend.
If you want to publish your school content, Strapi is an excellent option. In addition to supporting rich text, it also offers a user-friendly composition interface in the admin panel. The content can also be consumed by your school website via an API that is fully customizable. Check out this summary of Strapi's features on its website to find out more about what more it can provide. Finally, this application's source code is accessible on Github.
My specialty is designing and developing advanced applications for the Android platform, front-end development, and writing technical blogs. I'm committed to providing high-level solutions that drive business and deliver outstanding cost efficiency. I love to code and study innovation topics.