# Craft twig guidelines

> Craft twig guidelines is an open-source agent skill for developer tools. Gives agents the Twig coding conventions and Craft helpers for Craft CMS 5 templates. It is available on Claude Code.

- **Kind:** Skill
- **Pricing:** Open source
- **Platforms:** Claude Code
- **Website:** https://github.com/michtio/craftcms-claude-skills/tree/main/skills/craft-twig-guidelines
- **Repository:** https://github.com/michtio/craftcms-claude-skills
- **GitHub stars:** 91
- **License:** MIT
- **Skill name:** craft-twig-guidelines
- **Collection:** https://github.com/michtio/craftcms-claude-skills
- **Categories:** [developer tools](https://ai-powered.com/categories/developer-tools)
- **Listing updated:** 2026-12-03

## About

This skill sets out coding standards for Twig templates in Craft CMS 5 projects, covering atomic components, views, layouts and partials. It guides naming, null handling with the null-coalescing operators, whitespace control, isolating included partials, and writing component file headers. It also explains which Craft Twig helpers to prefer, such as tag(), attr(), svg() and collect(), and how to build class strings from named keys instead of string concatenation.

The skill ships a reference set that the agent reads on demand: core conventions with correct and wrong examples, a guide to Craft helper functions, and notes for upgrading to Craft 5.12. A short bash script reports the project's Craft version when the skill loads, so version-specific advice matches the site. It also lists common pitfalls, such as snake_case variables, missing include scoping and hardcoded colours.

Using it assumes a Craft CMS 5 project with Twig templates. Template architecture, routing and content modelling are handled by companion skills, and PHP standards by a separate PHP guidelines skill.

## When your agent uses it

> Twig coding standards and conventions for Craft CMS 5 templates. ALWAYS load this skill when writing, editing, or reviewing any .twig file in a Craft CMS project, even for small edits. Covers: variable naming (camelCase, no abbreviations), null handling (?? operator, ??? with empty-coalesce plugin), whitespace control ({%- trimming, NOT {%- minify -%}), include isolation (always 'only'), Craft Twig helpers ({% tag %}, tag(), attr(), |attr, |parseAttr, |append, svg()), collect() for props and class collections, .implode(), ========= comment headers on component files, and pitfalls (snake_case, macros as components, hardcoded colors).

## What it can access

From a static check of the files on GitHub; nothing was run.

- [Runs shell scripts](https://github.com/michtio/craftcms-claude-skills/tree/HEAD/skills/craft-twig-guidelines)
- [Asks for: Bash(sh ${CLAUDE_SKILL_DIR}/scripts/craft-version.sh)](https://github.com/michtio/craftcms-claude-skills/blob/HEAD/skills/craft-twig-guidelines/SKILL.md)
- [No network calls found in its scripts](https://github.com/michtio/craftcms-claude-skills/tree/HEAD/skills/craft-twig-guidelines)
- [License: MIT](https://github.com/michtio/craftcms-claude-skills/tree/HEAD/skills/craft-twig-guidelines)

## Features

- **Naming and null handling:** Covers camelCase variable names, avoiding abbreviations, and when to use the null-coalescing operators.
- **Include isolation rules:** Requires the only keyword on includes and renders so components do not depend on parent variables.
- **Craft Twig helpers:** Explains tag(), attr(), svg() and collect() usage for polymorphic elements and class strings.
- **Whitespace control:** Shows where to trim output whitespace and why the minify tag is deprecated.
- **Component file headers:** Defines a standard comment header format for component, view and layout files.
- **Version-specific upgrade notes:** Lists behaviour changes and deprecations for Craft 5.10 through 5.12 and Twig 3.29 to 3.31.

## Good for

- Review a Twig component for snake_case variables and missing include scoping
- Refactor class string concatenation into collect() with named keys
- Write a Craft Twig partial with proper whitespace control and a comment header
- Check a template for hardcoded colours and replace them with theme classes
- Upgrade a Twig template to use heading() or render() on Craft 5.12

## Install

### Claude Code

This skill ships in the `craftcms-claude-skills` plugin. In Claude Code, add the marketplace and install the plugin (it may include other skills too):

```sh
/plugin marketplace add michtio/craftcms-claude-skills
/plugin install craftcms-claude-skills@craftcms-claude-skills
```

Or copy only this skill to `~/.claude/skills/craft-twig-guidelines`:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/michtio/craftcms-claude-skills.git "$tmp" &&
mkdir -p ~/.claude/skills &&
rm -rf ~/.claude/skills/craft-twig-guidelines &&
cp -R "$tmp/skills/craft-twig-guidelines" ~/.claude/skills/craft-twig-guidelines &&
rm -rf "$tmp"
```

For one project only, put the folder in `.claude/skills/craft-twig-guidelines` inside it instead.

### Codex

Copy the skill folder to `~/.agents/skills/craft-twig-guidelines` to use it in every repository:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/michtio/craftcms-claude-skills.git "$tmp" &&
mkdir -p ~/.agents/skills &&
rm -rf ~/.agents/skills/craft-twig-guidelines &&
cp -R "$tmp/skills/craft-twig-guidelines" ~/.agents/skills/craft-twig-guidelines &&
rm -rf "$tmp"
```

For one repository only, put the folder in `.agents/skills/craft-twig-guidelines` inside it instead.

### Cursor

Copy the skill folder to `~/.cursor/skills/craft-twig-guidelines` to use it in every project:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/michtio/craftcms-claude-skills.git "$tmp" &&
mkdir -p ~/.cursor/skills &&
rm -rf ~/.cursor/skills/craft-twig-guidelines &&
cp -R "$tmp/skills/craft-twig-guidelines" ~/.cursor/skills/craft-twig-guidelines &&
rm -rf "$tmp"
```

For one project only, put the folder in `.cursor/skills/craft-twig-guidelines` inside it instead.

### Gemini CLI

Run in a terminal (add `--scope workspace` to install it for the current workspace only):

```sh
gemini skills install https://github.com/michtio/craftcms-claude-skills.git --path skills/craft-twig-guidelines
```

Or copy the folder to `~/.gemini/skills/craft-twig-guidelines` yourself.

### VS Code

For GitHub Copilot in VS Code, copy the skill folder to `~/.copilot/skills/craft-twig-guidelines`:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/michtio/craftcms-claude-skills.git "$tmp" &&
mkdir -p ~/.copilot/skills &&
rm -rf ~/.copilot/skills/craft-twig-guidelines &&
cp -R "$tmp/skills/craft-twig-guidelines" ~/.copilot/skills/craft-twig-guidelines &&
rm -rf "$tmp"
```

For one project only, put the folder in `.github/skills/craft-twig-guidelines` inside it instead.

### Other agents

Get the folder:

```sh
git clone --depth 1 https://github.com/michtio/craftcms-claude-skills.git
```

Then copy `craftcms-claude-skills/skills/craft-twig-guidelines` into your agent's skills folder as `craft-twig-guidelines`. Agents that support SKILL.md read one folder per skill.

## FAQ

### What does the skill need to run?

It runs a bash script that reads the project's Craft version, so it needs a shell and a Craft CMS 5 project.

### When does Craft twig guidelines trigger?

It is meant to load whenever a .twig file is written, edited or reviewed in a Craft CMS project, even for small edits.

### Does Craft twig guidelines cover template architecture or PHP?

No. Architecture and routing are covered by the craft-site skill, content modelling by craft-content-modeling, and PHP by craft-php-guidelines.

### How do I install Craft twig guidelines in Claude Code?

Copy the skill folder from GitHub to ~/.claude/skills/craft-twig-guidelines to use it in all your projects, or to .claude/skills/craft-twig-guidelines in one project. Or install the craftcms-claude-skills plugin, which includes it: /plugin marketplace add michtio/craftcms-claude-skills, then /plugin install craftcms-claude-skills@craftcms-claude-skills.

### Does Craft twig guidelines run scripts?

Yes. It runs shell scripts. No network calls were found in its scripts. This comes from a static check of the files on GitHub; nothing was run. Read the files before you install it.

### Which AI agents can use Craft twig guidelines?

Claude Code. It reads skills in the SKILL.md format; the install steps on this page show where to put the folder.

### What are the best alternatives to Craft twig guidelines?

The closest alternatives to Craft twig guidelines are Craft site, Craft php guidelines, Craftcms, Craft garnish and Craft content modeling.

## Where this comes from

- Description: from the skill's own SKILL.md.

## Alternatives

- [Craft site](https://ai-powered.com/skills/craft-site): Craft site is an open-source agent skill for design and media.
- [Craft php guidelines](https://ai-powered.com/skills/craft-php-guidelines): Craft php guidelines is an open-source agent skill for developer tools.
- [Craftcms](https://ai-powered.com/skills/craftcms): Craftcms is an open-source agent skill for developer tools.
- [Craft garnish](https://ai-powered.com/skills/craft-garnish): Craft garnish is an open-source agent skill for developer tools.
- [Craft content modeling](https://ai-powered.com/skills/craft-content-modeling): Craft content modeling is an open-source agent skill for developer tools.
- [Craft plugins](https://ai-powered.com/skills/craft-plugins): Craft plugins is an open-source agent skill for developer tools.
- [Coding standards](https://ai-powered.com/skills/coding-standards-fmarzochi): Coding standards is an open-source agent skill for developer tools.
- [Coding standards](https://ai-powered.com/skills/coding-standards-abdullayevtemurmalik): Coding standards is an open-source agent skill for developer tools.

---
Source: https://ai-powered.com/skills/craft-twig-guidelines
