Author component

As we just saw, the Card wide variant uses some information from the article author. We don't have a component for users or authors so we need to quickly build one.

  1. Inside src/patterns/components create a new folder called author

  2. Inside the author folder create author.json, author.twig, author.scss

  3. Add the code below to each of the respective files

{
  "author": {
    "photo": "<img src='https://source.unsplash.com/_cvwXhGqG-o/100x100' alt='Author's headshot' />",
    "name": "Valentina De Leon",
    "title": "Digital Strategist"
  }
}
{{ attach_library('training_theme/author') }}

<div class="author{{ modifier ? ' ' ~ modifier }}
  {{- attributes ? ' ' ~ attributes.class -}}"
  {{- attributes ? attributes|without(class) -}}>
  <div class="author__meta">
    <div class="author__name">{{ author.name }}</div>
    <div class="author__title">{{ author.title }}</div>
  </div>
  <div class="author__photo">{{ author.photo }}</div>
</div>
  • Create the author library in training_theme.libraries.yml.

Update the Card component with new Author component

Let's update the card component so we make use of the newly built Author component.

  1. Edit card.twig by replacing the current code for author information with the code below:

  1. Rebuild your theme by running

Windows users may need to run the two commands above separately (npm run build then npm run watch

Full Card code

Last updated

Was this helpful?