moodle — GitHub Copilot rule: Moodle code that fits the core
This rule tells Copilot how to write Moodle code: Frankenstyle namespaces, Mustache templates, mandatory security functions. Useful when you build plugins or themes.
.github/instructions/moodle.instructions.mdWhat moodle does
The file frames the repository as a Moodle project and asks Copilot to match the core version you actually run. It lists the plugin layout: /db, /lang, /classes, /templates, plus /version.php, /settings.php and /lib.php when needed. Classes get a namespace tied to the component — local_myplugin, mod_forum, block_mycatalog.
Security gets its own section. Database calls go through $DB with placeholders, access checks use require_login() and require_capability(), and request parameters come from required_param() or optional_param(). HTML belongs in renderers and Mustache, not inside PHP. JavaScript uses AMD modules, not inline scripts.
The rule applies to **/*.php, **/*.js, **/*.mustache, **/*.xml, **/*.css and **/*.scss. One thing to watch: PHP has to stay compatible with the core version, and newer syntax breaks that. So Copilot won't hand you a Moodle function that doesn't exist.
What it helps with
- scaffold a local plugin with version.php and settings.php
- add a table in db/install.xml plus an upgrade script
- build a form with moodleform
- render a table through a renderer and Mustache
- wire capability and parameter checks the Moodle way
Example prompts for the agent
- Generate a basic local plugin with version.php, settings.php, and lib.php
- Create a new table in db/install.xml and an upgrade script in db/upgrade.php
- Create a renderer with Mustache to display a table
How to install moodle
Manually: put the files in place
.github/instructions/moodle.instructions.mdThe applyTo field sets which files it applies to
Manually: put the files in place
.claude/rules/moodle.mdThe paths frontmatter field limits the files: move applyTo from the source into paths
AGENTS.md
Codex reads AGENTS.md: paste the rule text there
Manually: put the files in place
.cursor/rules/moodle.mdcFrontmatter: description, globs, alwaysApply. Move applyTo from the source into globs, or the rule will not attach on its own
Manually: put the files in place
.devin/rules/moodle.mdManually: put the files in place
.clinerules/moodle.mdStep by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use
Questions about moodle
How do I install the moodle rule in GitHub Copilot?
Place the file at .github/instructions/moodle.instructions.md in your repository. Copilot picks it up for the files listed in applyTo.
What does the moodle rule do?
It gives Copilot Moodle project context: plugin structure, Frankenstyle namespaces, $DB usage and security functions, HTML only in Mustache.
Which files does the rule cover?
**/*.php, **/*.js, **/*.mustache, **/*.xml, **/*.css and **/*.scss — that's what applyTo lists.
Source text
moodle.instructions.md · MIT
--- applyTo: '**/*.php, **/*.js, **/*.mustache, **/*.xml, **/*.css, **/*.scss' description: 'Instructions for GitHub Copilot to generate code in a Moodle project context.' --- # Project Context This repository contains a Moodle project. Ensure that any generated code is compatible with the specific Moodle version used in this project (for example, Moodle 3.11, 4.1 LTS, or later). It includes: - Plugin development (local, block, mod, auth, enrol, tool, etc.) - Theme customization - CLI scripts - Integrations with external services using the Moodle API # Code Standards - Follow the official Moodle Coding guidelines: https://moodledev.io/general/development/policies/codingstyle - PHP must be compatible with the core version (e.g., PHP 7.4 / 8.0 / 8.1). - Do not use modern syntax that is not supported by core if it breaks compatibility. - Class naming must use Moodle namespaces. - Follow Moodle’s standard plugin directory layout (for example: classes/output, classes/form, db/, lang/, templates/…). - Mandatory use of Moodle security functions: - `$DB` with SQL placeholders - `require_login()`, `require_capability()` - Parameters handled with `required_param()` / `optional_param()` # Code Generation Rules - When creating new PHP classes in plugins, use the Moodle component (Frankenstyle) namespace that matches the plugin's component name, e.g. `local_myplugin`, `mod_forum`, `block_mycatalog`, `tool_mytool`. - In plugins, always respect the structure: - /db - /lang - /classes - /templates - /version.php - /settings.php - /lib.php (only if necessary) - Use renderers and Mustache templates for HTML. Do not mix HTML inside PHP. - In JavaScript code, use AMD modules, not inline scripts. - Prefer Moodle API functions over manual code whenever possible. - Do not invent Moodle functions that do not exist. # Examples of What Copilot Should Be Able to Answer - "Generate a basic local plugin with version.php, settings.php, and lib.php." - "Create a new table in db/install.xml and an upgrade script in db/upgrade.php." - "Generate a Moodle form using moodleform." - "Create a renderer with Mustache to display a table." # Expected Style - Clear and specific answers in the Moodle context. - Always include files with full paths. - If there are multiple ways to do something, use the approach recommended by Moodle.
© github · MIT · github/awesome-copilot