# Slots Slots allow you to define areas in your components where content can be inserted when the component is used. This feature provides flexibility and reusability to your components. ## Default Slot Every component in django-bird has a default slot. There are three ways to reference this default slot in your component template: 1. `{{ slot }}` 2. `{% bird:slot %}{% endbird:slot %}` 3. `{% bird:slot default %}{% endbird:slot %}` These are all equivalent and will render the content placed between the opening and closing tags of your component when it's used. Let's look at each approach: Using `{{ slot }}`: ```{code-block} htmldjango :caption: templates/bird/button.html ``` Alternatively, you can use `{% bird:slot %}{% endbird:slot %}`: ```{code-block} htmldjango :caption: templates/bird/button.html ``` Or, you can explicitly name the default slot with `{% bird:slot default %}{% endbird:slot %}`: ```{code-block} htmldjango :caption: templates/bird/button.html ``` When using any of these component templates, you would write: ```htmldjango {% bird button %} Click me {% endbird %} ``` And the output would be: ```html ``` All three versions of the component template will produce the same output. Choose the syntax that you find most readable or that best fits your specific use case. ## Named Slots In addition to the default slot, you can define named slots for more complex component structures. Named slots allow you to create more flexible and reusable components by specifying multiple areas where content can be inserted. ### Basic Usage Here's a basic example of a component with a named slot: ```{code-block} htmldjango :caption: templates/bird/button.html ``` To use this component with a named slot: ```htmldjango {% bird button %} {% bird:slot leading-icon %} {% endbird:slot %} Click me {# This content goes into the default slot #} {% endbird %} ``` This would output: ```html ``` ### Checking for Slot Content django-bird provides a `slots` variable in the template context that allows you to check if a certain slot has been passed in. This can be useful for conditional rendering or applying different styles based on whether a slot is filled. Here's an example of how you might use this: ```{code-block} htmldjango :caption: templates/bird/button.html ``` Now, you can use this component in different ways: ```htmldjango {% bird button %} Click me {% endbird %} ``` This would output: ```html ``` But if you include the `leading-icon` slot: ```htmldjango {% bird button %} {% bird:slot leading-icon %} {% endbird:slot %} Click me {% endbird %} ``` It would output: ```html ``` ### Multiple Named Slots You can define as many named slots as you need in a component. Here's an example with multiple named slots, demonstrating different ways to reference slot content: ```{code-block} htmldjango :caption: templates/bird/card.html