Prereqs (optional if already installed)
๐งโโ๏ธ Epic Introduction¶
In the vast digital matrix where data flows like rivers of light, an ancient archway awaits. Step through and behold The Temple of Templatesโa sanctum where binary incantations become architecture and reusable patterns are carved in code like sacred runes. Here, temples and templates are kindred artifacts: both are blueprints that outlive their makers, both embed deep wisdom for future builders, and both scale from humble shrines to sprawling cathedrals (or from scripts to systems). Today, youโll learn to forge reusable components across stacks, weaving type-safety, composition, and inheritance into an elegant tapestry of maintainable software.
๐ The Legend Behind This Quest¶
From Angkor Wat to the Parthenon, great temples were designed with symmetry, purpose, and expansion in mind. Likewise, template-driven codeโC++ generics, HTML/Jinja templates, React componentsโcreates structures that endure change. Your mission: master the patterns that let small ideas grow into resilient systems.
๐ฏ Quest Objectives¶
Primary Objectives¶
- Design and implement a reusable template in one stack (C++ OR Jinja OR React)
- Demonstrate composition and extension (inheritance or template inheritance)
- Explain trade-offs between abstraction depth and simplicity (KIS vs. flexibility)
Secondary Objectives (Bonus)¶
- Build two stacks (e.g., Jinja and React) using a shared content model
- Add automated tests or validation (snapshot test, render check, or compile-time proof)
- Publish a README that teaches another adventurer the pattern
Mastery Indicators¶
- You can describe when to choose composition over inheritance
- You can extend a template without modifying its source
- You can identify and avoid over-abstracted โtemple sprawlโ
๐ Choose Your Adventure Platform¶
Pick one pathโor explore them all. Each grants similar powers with different spellbooks.
๐ macOS Kingdom Path¶
# Prereqs (optional if already installed)
brew install python node git
python3 -m venv .venv && source .venv/bin/activate
python -m pip install jinja2
npm install -g create-vite @vitejs/plugin-react
๐ช Windows Empire Path¶
# Run in PowerShell
winget install -e --id Python.Python.3.12
winget install -e --id OpenJS.NodeJS
pip install jinja2
npm install -g create-vite @vitejs/plugin-react
๐ง Linux Territory Path¶
sudo apt-get update && sudo apt-get install -y python3-venv python3-pip nodejs npm
python3 -m venv .venv && source .venv/bin/activate
pip install jinja2
npm install -g create-vite @vitejs/plugin-react
โ๏ธ Cloud Realms Path¶
- Use GitHub Codespaces or a dev container with Node 18+ and Python 3.10+
- Optional: Dockerize a tiny Jinja renderer for reproducible builds
๐ฑ Universal Web Path¶
- Use StackBlitz (React) and a web-based Jinja playground alternative for quick experiments
๐งโโ๏ธ Chapter 1: Foundation Stones โ Abstraction as Bedrock¶
โ๏ธ Skills Youโll Forge โ Chapter 1¶
- Understand what โtemplateโ means across languages
- Recognize compile-time vs. render-time vs. runtime templating
- Choose safe defaults to avoid over-engineering
๐๏ธ Building Your Knowledge Foundation¶
๐ง Implementation: C++ Generic Vector (compile-time template)¶
Purpose: Demonstrate type-parametric reuse and inlineable performance. Prerequisites: A modern C++ compiler.
// Minimal illustrative example: a typed Box
template <typename T>
struct Box {
T value;
explicit Box(T v) : value(v) {}
T get() const { return value; }
};
// Usage
// Box<int> bi(42);
// Box<std::string> bs("runes");
Key Insight: Compile-time templates offer zero-cost abstractions but raise error complexity. Prefer clear errors via concepts/constraints when available.
๐ง Implementation: HTML with Jinja2 (render-time template)¶
Purpose: Separate content from structure with inheritance and blocks. Prerequisites: Python 3 with Jinja2.
# render.py
from jinja2 import Environment, FileSystemLoader
env = Environment(loader=FileSystemLoader('templates'))
print(env.get_template('page.html').render(title='Temple of Templates', user={'name':'Acolyte'}))
<!-- templates/base.html -->
<!doctype html>
<html>
<head><title>{% raw %}{% block title %}{% endraw %}Base{% raw %}{% endblock %}{% endraw %}</title></head>
<body>
<header>๐๏ธ {% raw %}{{ site_name | default('Temple') }}{% endraw %}</header>
<main>{% raw %}{% block content %}{% endraw %}{% raw %}{% endblock %}{% endraw %}</main>
</body>
</html>
<!-- templates/page.html -->
{% raw %}{% extends 'base.html' %}{% endraw %}
{% raw %}{% block title %}{% endraw %}{% raw %}{{ title }}{% endraw %}{% raw %}{% endblock %}{% endraw %}
{% raw %}{% block content %}{% endraw %}
<h1>Hello {% raw %}{{ user.name }}{% endraw %}!</h1>
{% raw %}{% endblock %}{% endraw %}
Expected Output:
๐ง Implementation: React Component Template (runtime component)¶
Purpose: Compose UI with props and slots. Prerequisites: Node.js + a React starter.
// Card.jsx
export function Card({ title, children }) {
return (
<section className="card">
<h2>{title}</h2>
<div>{children}</div>
</section>
);
}
// Usage
// <Card title="Sanctum"><p>Rendered content</p></Card>
Common Pitfalls¶
- C++: unreadable template errors โ use constraints/concepts
- Jinja: tight coupling to data shape โ validate inputs
- React: prop drilling โ prefer composition and context
๐ Knowledge Check โ Chapter 1¶
- What differences matter between compile-time, render-time, and runtime templating?
- How would you refactor if the data model changes?
๐งโโ๏ธ Chapter 2: Sacred Carvings โ Embedding Reusable Wisdom¶
โ๏ธ Skills Youโll Forge โ Chapter 2¶
- Template inheritance and block overrides
- Composition over inheritance (where practical)
- Encapsulating defaults with extension points
๐ง Implementation: Jinja Inheritance + Partials¶
<!-- templates/partials/button.html -->
<button class="btn {% raw %}{{ variant | default('primary') }}{% endraw %}">{% raw %}{{ label }}{% endraw %}</button>
<!-- templates/page.html (extended) -->
{% raw %}{% extends 'base.html' %}{% endraw %}
{% raw %}{% block content %}{% endraw %}
{% raw %}{% include 'partials/button.html' with context %}{% endraw %}
{% raw %}{% endblock %}{% endraw %}
๐ง Implementation: React Composition¶
// Layout.jsx
export function Layout({ header, children }) {
return (
<div>
<header>{header}</header>
<main>{children}</main>
</div>
);
}
// <Layout header={<Logo/>}><Dashboard/></Layout>
๐ Knowledge Check โ Chapter 2¶
- Where is inheritance appropriate? Where is composition safer?
- How do partials/slots keep templates stable as features grow?
๐งโโ๏ธ Chapter 3: Inner Sanctum โ Blueprints for the Future¶
โ๏ธ Skills Youโll Forge โ Chapter 3¶
- Extensibility patterns (slots/blocks/hooks)
- Guardrails (linters, tests, constraints)
- Documentation as part of the artifact
๐ง Implementation: Constraints (C++)¶
#include <concepts>
template <typename T>
requires std::totally_ordered<T>
T max_of(T a, T b) { return a < b ? b : a; }
๐ง Implementation: Snapshot Test (React)¶
// Example with Vitest/RTL (outline)
// render(<Card title="Relic">text</Card>)
// expect(screen.getByText('Relic')).toBeInTheDocument()
๐งช Experimentation Station¶
- Swap data models and confirm templates still render
- Add a new block/slot without touching the base implementations
๐ฎ Quest Implementation Challenges¶
Challenge 1: Temple Landing (๐ 25โ35 min)¶
Objective: Render a landing page from a base layout. Requirements:
- Base layout + page override (Jinja OR React)
- One reusable partial/component (button/card)
- README explaining structure and how to extend
Success Criteria:
- Page renders with dynamic title
- Partial is reused twice with different props/context
Challenge 2: Dual-Temple Build (๐ 25โ35 min)¶
Objective: Implement the same layout in a second stack. Requirements:
- Mirror layout and content model
-
Note differences (props vs. context; server vs. client render) Success Criteria:
-
Both stacks produce equivalent UI
- Document trade-offs (performance, complexity)
๐ Master Challenge: Pattern Codex (๐ 30โ45 min)¶
Objective: Create a small pattern library (2โ3 components/partials) with usage examples and tests or constraints.
โ Quest Completion Verification¶
- At least one working stack with inheritance/composition
- Clear explanation of pattern choices and trade-offs
- Repo/gist link with README and runnable steps
๐ Quest Rewards and Achievements¶
๐ Achievement Badges Earned¶
- Pattern Weaver โข Template Mastery โข Abstraction Adept
โก Skills and Abilities Unlocked¶
- Confidently select the right templating layer
- Build once, extend many times with minimal churn
๐ ๏ธ Tools Added to Your Arsenal¶
- C++ templates, Jinja2, React components, testing/constraints
๐ Your Journey Progress¶
- Previous: Programming Foundations โ Functions and Modules
- Current: Level 1100 (12) Function Crafting
- Next: Integration Spells (APIs) or Testing Trials
๐ฎ Your Next Epic Adventures¶
- Level 1100: Composition over InheritanceโA Practical Guide
- Level 1101: Testing the SanctumโVerification for Templates
- Level 1110: Security SigilsโSanitization and Safe Rendering
๐ Quest Resource Codex¶
๐ Essential Documentation¶
- C++ Templates: https://en.cppreference.com/w/cpp/language/templates
- Jinja2: https://jinja.palletsprojects.com/
- React Components: https://react.dev/learn/describing-the-ui
๐ฅ Visual Learning Resources¶
- Templates & Composition talks (search: โcomposition over inheritance reactโ)
๐ฌ Community and Support¶
- Stack Overflow: c++, jinja2, reactjs tags
- Reactiflux Discord; Python Discord (Jinja channel)
๐ง Tools and Extensions¶
- VS Code: Jinja, C/C++, ESLint, React snippets
๐ Cheat Sheets and References¶
- C++ concepts quick ref; Jinja filters; React props/children patterns
๐บ๏ธ Quest Network Position¶
Quest Series: Binary Function Crafting Prerequisites:
- Level 0011: Programming Basics
- Level 0100: Git Fundamentals
Follow-Up Quests:
- Level 1101: Testing and QA Patterns
- Level 1100: Pattern Libraries and Design Systems
๐งญ Mermaid Wayfinding¶
graph TD
A[๐ฐ Quest Start] --> B{๐งโโ๏ธ Choose Path}
B -->|C++| C[Compile-time Templates]
B -->|Jinja| D[Render-time Templates]
B -->|React| E[Runtime Components]
C --> F[โ๏ธ Challenge 1]
D --> F
E --> F
F --> G{โ
Success?}
G -->|Yes| H[๐ Rewards]
G -->|No| I[๐ง Debug & Retry]
I --> F
H --> J[๐ฎ Next Quest]
๐ง Knowledge Check¶
Before you depart the temple, ensure you can explain:
- Why templates/components reduce duplication yet can increase cognitive load
- How to add extension points without breaking consumers
- When to stop abstractingโwhat is โgood enoughโ for today
May your blueprints be clear, your APIs stable, and your sanctums extensible. ๐๏ธ๐ก
๐ธ๏ธ Knowledge Graph¶
Structured wiki-links connect this quest to the IT-Journey knowledge graph. Open the Obsidian Graph View to explore connections.
Level hub: [[Level 1100 - Data & Templates]] Overworld: [[๐ฐ Overworld - Master Quest Map]] Obsidian docs: [[Obsidian Knowledge Graph and Wiki Links]]