# Templ Syntax

> Learn and write templ component syntax including expressions, conditionals, loops, and Go integration. Use when writing .templ files, learning templ syntax, or mentions 'templ component', 'templ expressions', or '.templ file syntax'.

- **Type:** Skill
- **Install:** `agentstack add skill-xe-skills-templ-syntax`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [Xe](https://agentstack.voostack.com/s/xe)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [Xe](https://github.com/Xe)
- **Source:** https://github.com/Xe/skills/tree/main/skills/templ-syntax

## Install

```sh
agentstack add skill-xe-skills-templ-syntax
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# Templ Syntax

Use this skill with progressive disclosure: start at Level 1, then read deeper sections only when needed.

## Level 1: Fast Path

Use this skill when you need to write or fix `.templ` syntax.

1. Define a component with typed params.
2. Render values with `{ expr }`.
3. Compose components with `@OtherComponent(...)`.
4. Use Go control flow (`if`, `for`, `switch`) directly in markup.
5. Keep business logic in Go helpers, not inline in templates.

```templ
package components

templ Greeting(name string, isAdmin bool) {
    Hello, { name }
    if isAdmin {
        Admin mode
    }
}
```

## Level 2: Core Rules

- **Output:** `{ value }` auto-escapes text.
- **Dynamic attrs:** `class={ classes }`, `disabled?={ isDisabled }`.
- **Children:** accept with `{ children... }`, pass with block syntax.
- **Composition:** call components with `@Component(...)`.
- **Safety:** URLs should use safe helpers (for example `templ.URL(...)`) when appropriate.

## Level 3: Common Patterns

```templ
templ Card(title string) {
    
        { title }
        { children... }
    
}

templ UserList(users []string) {
    if len(users) == 0 {
        No users
    } else {
        
            for _, user := range users {
                { user }
            }
        
    }
}
```

## Escalate to Other Skills

- Building reusable UI APIs: use `templ-components`.
- Wiring templates to handlers/routes: use `templ-http`.
- Adding dynamic interactions: use `templ-htmx`.

## References

- Foundations: `resources/foundations.md`
- Patterns: `resources/patterns.md`
- Reference: `resources/reference.md`
- templ docs: https://templ.guide
- Syntax and expressions: https://templ.guide/syntax-and-usage/

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [Xe](https://github.com/Xe)
- **Source:** [Xe/skills](https://github.com/Xe/skills)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-xe-skills-templ-syntax
- Seller: https://agentstack.voostack.com/s/xe
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
