Display the event page
We're almost there. Now that you have extended the content model and all the elements are in place, you can open the website and view the event page.
You can see the event ID in the Details
section of the event details page. Go to Content Hub ONE and, on the menu bar, click Content
. From the Content type
filter list, click Event
, and then click the event to open its details page.
To display the event page:
-
In Visual Studio Code, open the starter kit repository and go to the /pages folder.
-
Make a copy of the index.tsx page and name it event.tsx.
-
In the function, export async function getStaticProps, add the line
const event = await getEventById('YOUR_EVENT_ID')
, inserting the event ID from your Content Hub ONE instance. -
Modify the header elements to display the event data:
-
Add the following import statements after line 2:
import Event from '../types/Events/events-type';
andimport RichText from '../components/Common/richText-component';
-
Update the event object to display the
h1
withevent.eventName
. -
Update
event.eventImage?.results[0]?.fileUrl
for the hero banner. -
Update
event.eventDescription
within a RichText Component. The event description is returned as a JSONContent object. Look at the[slug].tsx
file located in the /pages/Recipes folder to see that those JSONContent objects can be rendered using therichText-component
passing the JSONContent. -
Remove
import RecipeTeaserComponent from '../components/Recipe/recipeTeaser-component';
. -
Remove
RecipeTeaserComponent allRecipes={allHomepage[0].recipes}/
.
-
-
Run
npm run dev
.
The final code should look like this.
You can now navigate to http://localhost:3000/event
to open the website and verify that everything works.