DEV Community

S. Amir Mohammad Najafi
S. Amir Mohammad Najafi

Posted on • Originally published at Medium on

Mastering Eleventy Folder Structures: From Default Setups to Real-World Best Practices

Post cover

Introduction

Welcome to the exciting world of Eleventy, a powerful and flexible static site generator based on jamstack! Whether you’re a seasoned developer or just starting out, understanding how to effectively organize your Eleventy project is crucial for efficiency and scalability. In this guide, we’ll embark on a journey from the simplicity of Eleventy’s default folder structure to the sophistication of a customized setup tailored for more complex projects.

For the complete store, read the full article on my blog 🙌🏻. 🙌🏻

In-Depth Look at Eleventy’s Basic Setup

Eleventy, known for its simplicity and flexibility, starts users off with a straightforward folder structure. This design is particularly appealing to beginners or those looking to quickly set up a static site without the complexity often associated with such setups. Let’s delve deeper into each component of this default structure:

1. Input

The input directory is denoted by a dot (.), representing the current directory where the Eleventy command is run. This approach means that all the files and subdirectories within this directory are considered part of your project's source. It simplifies the process by not requiring a specific folder for your source files, allowing Eleventy to work with your project's root directory directly.

2. Includes

The _includes directory is where Eleventy looks for templating parts - reusable pieces of your templates, like headers, footers, and navigation bars. This feature is crucial for avoiding repetition, as it allows you to maintain consistent elements across various parts of your website easily. By default, Eleventy treats this folder as the go-to place for these template snippets, helping you to organize your project better. this folder where is you can use the include tag to include a template part in another template.

3. Layouts:

In Eleventy’s default setup, layouts are often placed in the same _includes directory. Layouts are essentially templates that define the structure of a webpage. By placing layouts in the _includes folder, Eleventy offers a streamlined approach, keeping all template-related files in one location. However, as projects grow, some developers prefer to separate layouts into their own directory for clearer distinction and organization

4. Global Data

The _data folder is a powerful feature in Eleventy. It's used for storing global data files that can be accessed by any template across the site. This could include site metadata, configuration settings, or any other data that needs to be available site-wide. The data in these files can be written in various formats like JSON, JavaScript, or YAML, providing flexibility in how you manage your site's content and settings.

5. Output: _site

Finally, the _site directory is the default output location where Eleventy generates the final, built version of your site. After running Eleventy, this folder contains the HTML, CSS, JavaScript, and other assets that make up your website, ready to be deployed to a web server or CDN. This separation of source and output is critical for maintaining a clean workspace, ensuring that your development files are kept separate from the deployable, built site.

Here’s the visual representation of this structure:

├── _data # Global data files
├── _includes # Template parts and layouts
├── . # Main input directory (root of your project)
└── _site # Output directory for the built website
Enter fullscreen mode Exit fullscreen mode

Understanding this default structure is key to getting started with Eleventy. It offers a balance of simplicity and organization, making it an ideal starting point for building static websites. As you grow more familiar with Eleventy, you may find ways to customize this structure to better suit the needs of more complex projects.

Implementing a Real-World Advanced Folder Structure

In the ever-evolving world of web development, Eleventy projects often outgrow their initial folder structures, revealing the need for a more sophisticated organization as they expand in complexity and size. This progression necessitates a refined approach to effectively handle a growing array of files, diverse content types, and the nuances of complex build processes. Embracing an advanced folder structure, fundamentally grounded in the Separation of Concerns (SoC) principle, becomes critical.

💡 Separation of Concerns : This pivotal design principle involves dividing a computer program into distinct sections, each focusing on a unique aspect of the software’s functionality. Applied to web development and particularly Eleventy projects, SoC means organizing files and folders to independently manage each type of file or functionality. This strategic compartmentalization significantly boosts a project’s readability, maintainability, and scalability. For a detailed exploration of SoC, Wikipedia provides extensive insights.

Crucially, in implementing this structure, remember that the essence lies in the functional separation of the folders rather than their specific names. Folder names can vary widely based on individual preferences or project requirements, underscoring the importance of a tailored approach to folder organization in Eleventy projects.

Continue reading the article on my blog 🙌🏻

continue reading on my blog

Top comments (0)