Skip to content

Instantly share code, notes, and snippets.

@webrgp
Last active April 8, 2025 13:49
Show Gist options
  • Save webrgp/ad0b7a9b039458768bc0d2a01ded1660 to your computer and use it in GitHub Desktop.
Save webrgp/ad0b7a9b039458768bc0d2a01ded1660 to your computer and use it in GitHub Desktop.
Craft 4 + Vite / Copilot Custom Instructions

Global Instructions

General Style

PHP Code

  • Use Craft’s service locator pattern to access services (e.g. Craft::$app->entries->getEntryById()).
  • Always use dependency injection in custom module constructors when possible.
  • All custom modules extend craft\base\Module and are registered in #folder/config/app.php.

Twig Templates

  • Twig templates are located in #folder/rebuild/templates.
  • Twig template files should follow the naming convention of *.twig.

Frontend

  • Frontend source files are located in #folder/src
  • Tailwind CSS is commonly used and included via Vite.
  • JS assets are typically compiled using Vite.

Craft Configuration

  • Environment variables are defined in #folder/.env files and accessed via App::env().
  • Project config is stored in #folder/config/project/.

Custom Modules

  • Custom modules live in #folder/modules/ and are registered in #folder/config/app.php.
  • Use PSR-4 autoloading via #folder/composer.json.
  • Avoid placing logic in controllers—prefer services or helper classes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment