Структура Craft CMS
🧠 Суть
Оптимальная структура проекта на Craft CMS для переиспользования и поддержки.
⚙️ Базовая структура
project/
├── config/
│ ├── general.php
│ ├── routes.php
│ └── project.yaml
├── modules/
│ └── SiteModule.php
├── templates/
│ ├── _layout.twig
│ ├── _partials/
│ │ ├── header.twig
│ │ ├── footer.twig
│ │ └── nav.twig
│ ├── _components/
│ │ ├── card.twig
│ │ └── modal.twig
│ ├── index.twig
│ └── error/
│ └── 404.twig
├── web/
│ ├── dist/ # Vite build output
│ └── uploads/ # User uploads
└── .env💻 Section Types
Single (одностраничник)
yaml
# project.yaml
sections:
home:
type: single
template: index
enableVersioning: falseChannel (новости, блог)
yaml
sections:
news:
type: channel
template: news/_entry
maxLevels: 1Structure (иерархия)
yaml
sections:
pages:
type: structure
template: pages/_entry
maxLevels: 3💻 Matrix/Neo Blocks
yaml
# Field: contentBlocks (Matrix)
blocks:
text:
fields:
content: { type: redactor }
image:
fields:
image: { type: assets, kind: images }
caption: { type: plainText }
quote:
fields:
text: { type: plainText }
author: { type: plainText }⚠️ Подводные камни
project.yamlне трекатьdateModified→ добавь в.gitignore- Neo blocks → не экспортируются через project.yaml полностью
- Asset transforms → кэшируются, не забывай
clear-caches
🚀 Best Practice
- Компоненты → отдельные файлы
_components/ - Layouts →
_layout.twig+ embeds - Env vars →
.env, не в конфиге - Project.yaml — для продакшена, в деве можно через админку