---
name: step-03-render
description: Inject data into HTML template and write final file
model: opus
next_step: steps/step-04-verify.md
---

# Step 3: Render HTML

## YOUR TASK

Inject FEATURE_DATA and EMBEDDED_ARTIFACTS into the HTML template and write the final file.

---

## PRE-RENDER CLEANUP (MANDATORY)

> **NEVER reuse a build script from a previous session.**
> Build scripts (`_build-html.js`, `generate-html.js`) are throwaway artifacts that bypass
> the skill's normalization logic (normalizeKpi, normalizeColumn, Format B-CANONICAL).
> Reusing them causes stale data and missed fixes.

```
Delete any existing build scripts in the project directory:
  rm -f _build-html.js generate-html.js build-html.js

This ensures the HTML is always generated from the current step-02 output,
not from a cached script that may use outdated mapping logic.
```

---

## EXECUTION SEQUENCE

### 1. Locate Template

```
1. Primary: ~/.claude/skills/business-analyse-html/html/ba-interactive.html
2. Fallback: templates/skills/business-analyse-html/html/ba-interactive.html (project CLI path)
3. IF neither found → BLOCKING ERROR: "HTML template not found"
```

### 2. Read Template

```
Read the full HTML template file.
Verify it contains placeholders: {{FEATURE_DATA}}, {{EMBEDDED_ARTIFACTS}}
```

### 3. Replace Placeholders

Serialize and inject:

```
1. {{FEATURE_DATA}}        → JSON.stringify(FEATURE_DATA, null, 2)
2. {{EMBEDDED_ARTIFACTS}}  → JSON.stringify(EMBEDDED_ARTIFACTS, null, 2)
3. {{APPLICATION_NAME}}    → metadata.applicationName
4. {{APPLICATION_ID}}      → metadata.applicationId
5. {{VERSION}}             → metadata.version
6. {{CREATED_AT}}          → ISO timestamp (now)
```

> Verify: grep for remaining `{{` to confirm ALL placeholders are replaced.

### 4. Determine Output Path

```
IF workflow.mode === "project" (multi-app):
  outputPath = "docs/business-analyse/v{version}/ba-interactive.html"
ELSE (single-app):
  outputPath = "docs/{app}/business-analyse/v{version}/ba-interactive.html"
```

### 5. Write File

```
1. Create parent directories if needed
2. Write the final HTML file to outputPath
3. Display: "HTML written: {outputPath} ({fileSize} bytes)"
```

---

## VALIDATION

- Template was found and read
- All placeholders replaced (no remaining `{{`)
- File written successfully

## NEXT STEP

Load: `steps/step-04-verify.md`
