Creating a List of Recipes
Using the Umami Demo profile, our Drupal site comes with a number of recipes. As a first step, let’s retrieve a collection of our recipes and display a list of their titles in a component.
Listing Recipes
Umami Recipes
- Deep mediterranean quiche
- Vegan chocolate and nut brownies
- Super easy vegetarian pasta bake
- Watercress soup
- Victoria sponge cake
- Gluten free pizza
- Thai green curry
- Crema catalana
- Fiery chili sauce
- Borscht with pork ribs
Adding Grid Styling
Rather than a default list, let’s add styling to display our titles in a grid of what will become cards.
Umami Recipes
Deep mediterranean quiche
Vegan chocolate and nut brownies
Super easy vegetarian pasta bake
Watercress soup
Victoria sponge cake
Gluten free pizza
Thai green curry
Crema catalana
Fiery chili sauce
Borscht with pork ribs
Adding Fields
That grid is looking pretty bare. It would be nice to display some of the other fields from our recipes like recipe difficulty, image, and a link to the detailed content.
Adding difficulty and a link based on the content’s path alias is pretty straightforward.
Umami Recipes
Moving on to the image, we’ll see field_media_image
within the relationships
property of the object, but the associated data essentially only includes an id
which is not referenced elsewhere in the object.
This is because field_media_image references another entity in Drupal.
To ensure the image data we need is also included in this API response, we’ll need to pass additional query string parameters as part of our fetch request. In the next section, we’ll see how the JSON:API Client can make this easy.