Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Eleventy By Example

You're reading from   Eleventy By Example Create powerful, performant websites with a static-first strategy

Arrow left icon
Product type Paperback
Published in May 2023
Publisher Packt
ISBN-13 9781804610497
Length 198 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Bryan Robinson Bryan Robinson
Author Profile Icon Bryan Robinson
Bryan Robinson
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Chapter 1: Setting Up Your Website 2. Chapter 2: Adding Data to Your 11ty Website FREE CHAPTER 3. Chapter 3: Deploying to a Static Site Host 4. Chapter 4: Building a Blog with Collections 5. Chapter 5: Creating Custom Shortcodes to Add Mixed Media to Markdown 6. Chapter 6: Building a Photography Site with the 11ty Image Plugin 7. Chapter 7: Building a Podcast Website with 11ty Plugins and Custom Outputs 8. Chapter 8: Creating a Static-Site Search with 11ty Serverless and Algolia 9. Chapter 9: Integrating 11ty with a Headless CMS 10. Chapter 10: Creating Custom 11ty Plugins 11. Index 12. Other Books You May Enjoy

Creating reusable includes

While the base layout is more maintainable, we can make it easier to reconfigure by breaking the layout down into smaller pieces called includes. These includes will be the beginning of taking the code and turning them into building blocks that can be remixed into different layouts as necessary.

To start, we need to identify the smaller pieces of the base template. Let’s create a header.html file in the src/_templates/includes directory and move all the HTML meta information and visible site header into that file. Everything from the DOCTYPE element to the header element should be removed from base.html and moved into the new file.

While we’re refactoring the header, let’s also move the <nav> element into its own include, as well. 11ty templates can be nested. This means we can include files inside other files. In this case, the header.html include can include navigation.html.

Create a navigation.html file in the includes...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at R$50/month. Cancel anytime