Skip to main content
Webhaven

Main navigation

  • Home
  • Who it's for
    • Drupal newcomers & learners
    • Drupal experts
    • Ambitious agencies
  • Features
  • Go to demo
  • Docs
  • Get launch notified
  • English
Just launched the Webhaven demo website. Check it out! 🚀

Breadcrumb

  1. Home
  2. Webhaven documentation
  3. Theming
  4. An example component

Documentation

  • Documentation
    • Welcome
  • Get started
    • What is Webhaven?
    • Installation
    • Roadmap
  • Theming
    • Introduction
    • Theme structure
    • Create your own custom theme
    • Single Directory Components (SDC)
    • Component structure
    • An example component
  • Handy resources
    • Drupal Canvas
    • Useful DDEV commands
    • Drupal site template

An example component

Now that we have learned all about the structure a Webhaven component let's dive into an actual example.

Poll

For this example will dive deeper into the poll component.

Webhaven depends on the drupal/poll module to add poll functionalities to every Webhaven website.

You can see a poll in action here: poll example.

We let Drupal know that it should load our Webhaven component. How do we do this? You'll notice poll.html.twig under /templates/system has the following code:

# Include the Webhaven poll component
{% include 'webhaven:poll' %}

Components structure

/poll
|
|- poll.twig
|- poll.component.yml
|- poll.scss

Poll.twig

{%
  set classes = [
  'poll-component',
  'viewmode-' ~ elements['#view_mode']|clean_class,
]
%}
<div{{ attributes.addClass(classes) }}>
  {% if content %}
    {{- content -}}
  {% endif %}
</div>

The poll.twig file renders the DOM structure for every poll, you'll notice we add classes to it to make it easier to layout.

Poll.component.yml

name: Poll
description: "Styling of the poll component"
props:
  type: object
  properties: {}

We define our poll component, you'll notice the poll component doesn't have any props defined. 

A component can have props and/or slots. If you want to learn more on props & slots I advice you to read this documentation page.

Poll.scss

@import "../../src/scss/init";

.poll-component {
  .poll {
    margin: 0 auto;
    background-color: var(--color-card-bg);
    padding: var(--spacing-8);
    border-radius: var(--border-radius);

    h3.poll-question {
      font-size: var(--font-2xl);
    }
  }
}

You'll notice there is an import, this makes sure every component that needs it gets access to all our css vars that are used. If you want to learn more on css vars I advice you to read this documentation page.

We then give some basic mark-up to the poll container and the poll title.

That's it! All other files will be automatically generated when you run npm run watch or npm run production. In this particular this this means the poll.css and poll.css.map files are automatically generated for the component.

On this page
Webhaven
Launch your next Drupal project in days, not weeks.

Links

  • Launch notification
  • Features
  • Discover the demo
  • Documentation
  • Showcase
  • Blog
  • Frequently asked questions
  • Roadmap
  • Get in touch

Follow on

  • drupal profile
  • linkedin profile
  • x-twitter profile
© 2026 Webhaven. All rights reserved.

Legal

  • Privacy policy
  • Terms of service
  • Login
Built with