docx-templates-3-conditional-content
Sub-skill of docx-templates: 3. Conditional Content.
Best use case
docx-templates-3-conditional-content is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Sub-skill of docx-templates: 3. Conditional Content.
Teams using docx-templates-3-conditional-content should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/3-conditional-content/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How docx-templates-3-conditional-content Compares
| Feature / Agent | docx-templates-3-conditional-content | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Sub-skill of docx-templates: 3. Conditional Content.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# 3. Conditional Content
## 3. Conditional Content
**If-Else Logic in Templates:**
```python
"""
Use conditionals to include or exclude content based on data.
"""
from docxtpl import DocxTemplate
from typing import Dict, Any, Optional
from dataclasses import dataclass
from enum import Enum
class ContractType(Enum):
FULL_TIME = "full_time"
PART_TIME = "part_time"
CONTRACTOR = "contractor"
class ConfidentialityLevel(Enum):
STANDARD = "standard"
HIGH = "high"
RESTRICTED = "restricted"
@dataclass
class EmployeeContract:
"""Employee contract data."""
employee_name: str
position: str
department: str
start_date: str
contract_type: ContractType
salary: float
bonus_eligible: bool
stock_options: Optional[int] = None
confidentiality_level: ConfidentialityLevel = ConfidentialityLevel.STANDARD
probation_period_months: int = 3
remote_work_allowed: bool = False
relocation_package: bool = False
def to_context(self) -> Dict[str, Any]:
"""Convert to template context with conditional flags."""
return {
"employee_name": self.employee_name,
"position": self.position,
"department": self.department,
"start_date": self.start_date,
"salary": f"${self.salary:,.2f}",
# Contract type flags for conditionals
"is_full_time": self.contract_type == ContractType.FULL_TIME,
"is_part_time": self.contract_type == ContractType.PART_TIME,
"is_contractor": self.contract_type == ContractType.CONTRACTOR,
"contract_type_display": self.contract_type.value.replace("_", " ").title(),
# Benefit flags
"bonus_eligible": self.bonus_eligible,
"has_stock_options": self.stock_options is not None,
"stock_options": self.stock_options,
# Additional terms
"confidentiality_level": self.confidentiality_level.value,
"is_high_confidentiality": self.confidentiality_level in [
ConfidentialityLevel.HIGH,
ConfidentialityLevel.RESTRICTED
],
"probation_period_months": self.probation_period_months,
"remote_work_allowed": self.remote_work_allowed,
"relocation_package": self.relocation_package
}
def render_contract(
template_path: str,
output_path: str,
contract: EmployeeContract
) -> None:
"""
Render contract with conditional sections.
Template syntax for conditionals:
{% if is_full_time %}
Full-time benefits section...
{% endif %}
{% if bonus_eligible %}
Bonus clause...
{% else %}
Standard compensation only.
{% endif %}
{% if is_high_confidentiality %}
Additional NDA requirements...
{% endif %}
"""
template = DocxTemplate(template_path)
context = contract.to_context()
template.render(context)
template.save(output_path)
def render_with_conditions(
template_path: str,
output_path: str,
data: Dict[str, Any]
) -> None:
"""
Render template with various conditional patterns.
Supported conditional patterns:
{% if condition %} ... {% endif %}
{% if condition %} ... {% else %} ... {% endif %}
{% if condition %} ... {% elif other %} ... {% else %} ... {% endif %}
{% if value > 100 %} ... {% endif %}
{% if value in list %} ... {% endif %}
"""
template = DocxTemplate(template_path)
template.render(data)
template.save(output_path)
# Example contract
contract = EmployeeContract(
employee_name="John Doe",
position="Senior Software Engineer",
department="Engineering",
start_date="February 1, 2026",
contract_type=ContractType.FULL_TIME,
salary=150000,
bonus_eligible=True,
stock_options=5000,
confidentiality_level=ConfidentialityLevel.HIGH,
remote_work_allowed=True
)
# render_contract("contract_template.docx", "john_doe_contract.docx", contract)
def create_conditional_report(
template_path: str,
output_path: str,
performance_data: Dict
) -> None:
"""
Create report with conditional formatting based on performance.
Template example:
Performance Score: {{ score }}
{% if score >= 90 %}
OUTSTANDING PERFORMANCE
{% elif score >= 75 %}
MEETS EXPECTATIONS
{% elif score >= 60 %}
NEEDS IMPROVEMENT
{% else %}
PERFORMANCE PLAN REQUIRED
{% endif %}
{% if has_warnings %}
Warnings:
{%p for warning in warnings %}
- {{ warning }}
{%p endfor %}
{% endif %}
"""
template = DocxTemplate(template_path)
# Add computed flags to context
score = performance_data.get("score", 0)
context = {
**performance_data,
"performance_level": (
"Outstanding" if score >= 90 else
"Meets Expectations" if score >= 75 else
"Needs Improvement" if score >= 60 else
"Below Expectations"
),
"has_warnings": len(performance_data.get("warnings", [])) > 0
}
template.render(context)
template.save(output_path)
```Related Skills
skill-dedup-collision-reconciliation-with-content-security-scan
Reconcile duplicate/colliding workspace-hub skills without losing useful content, while avoiding pre-commit skill-content security scan regressions.
plan-review-rerun-cli-drift-and-git-contention
Recover iterative plan-review work when provider CLI wrappers drift, fresh reviews expose stale governance text, and active git pre-push processes make committing unsafe.
youtube-content
Fetch YouTube video transcripts and transform them into structured content (chapters, summaries, threads, blog posts). Use when the user shares a YouTube URL or video link, asks to summarize a video, requests a transcript, or wants to extract and reformat content from any YouTube video.
docx
Comprehensive Word document toolkit for reading, creating, and editing .docx files. Supports text extraction, document creation with python-docx, and tracked changes via redlining workflow. Use for legal, academic, or professional document manipulation.
content-strategy
Content marketing strategy with brand voice, editorial calendar, and content frameworks. Use for blog planning, content creation pipelines, and brand consistency. Based on alirezarezvani/Codex-skills.
skill-creator-content-quality
Sub-skill of skill-creator: Content Quality (+3).
n8n-8-workflow-templates-and-subworkflows
Sub-skill of n8n: 8. Workflow Templates and Subworkflows.
n8n-4-conditional-branching-and-error-handling
Sub-skill of n8n: 4. Conditional Branching and Error Handling.
activepieces-4-branching-and-conditional-logic
Sub-skill of activepieces: 4. Branching and Conditional Logic.
webapp-testing-wait-for-dynamic-content
Sub-skill of webapp-testing: Wait for Dynamic Content (+5).
github-swarm-pr-1-pr-templates-for-swarm
Sub-skill of github-swarm-pr: 1. PR Templates for Swarm.
github-swarm-issue-issue-templates-for-swarms
Sub-skill of github-swarm-issue: Issue Templates for Swarms.