feat(wiki): wiki templates — reusable content blocks via transclusion #671

Closed
opened 2026-06-21 06:34:10 +00:00 by jmiller · 0 comments
Owner

Summary

Add a wiki template system allowing reusable content blocks that can be embedded in wiki pages with parameters, similar to Wikipedia's template transclusion ({{Infobox|key=value}}).

Current State

No template or transclusion system exists. Repeated content must be manually duplicated across wiki pages.

Design

Template Pages

  • Pages stored under _Template/ prefix are templates (e.g., _Template/Infobox.md, _Template/Warning.md)
  • Template pages are hidden from the regular page list and sidebar tree
  • Templates are editable through the normal wiki editor

Transclusion Syntax

{{template:Infobox|title=MokoGitea|type=Software|license=MIT}}
{{template:Warning|message=This page is under construction}}
{{template:NavBox}}

Parameter Substitution

Inside template files, parameters are referenced as {{{title}}}, {{{message}}}, etc.:

<!-- _Template/Warning.md -->
> **Warning:** {{{message}}}

Implementation

  • Pre-processor: Before markdown rendering in renderViewPage(), scan the content for {{template:...}} patterns
  • Resolve: Load the template file from the wiki git repo, substitute parameters, and inline the result
  • Recursive: Templates can include other templates (with depth limit to prevent infinite loops)
  • Cache: Template content cached per wiki commit SHA

Files to Modify

File Change
routers/web/repo/wiki.go Template pre-processing step in renderViewPage()
services/wiki/wiki_template.go New — template resolution, parameter substitution
templates/repo/wiki/view.tmpl Hide _Template/ pages from sidebar

Wikipedia Parity

Wikipedia has over 60 million template transclusions. Templates are fundamental to maintaining consistent formatting, navigation boxes, infoboxes, and standardized notices across a wiki.

## Summary Add a wiki template system allowing reusable content blocks that can be embedded in wiki pages with parameters, similar to Wikipedia's template transclusion (`{{Infobox|key=value}}`). ## Current State No template or transclusion system exists. Repeated content must be manually duplicated across wiki pages. ## Design ### Template Pages - Pages stored under `_Template/` prefix are templates (e.g., `_Template/Infobox.md`, `_Template/Warning.md`) - Template pages are hidden from the regular page list and sidebar tree - Templates are editable through the normal wiki editor ### Transclusion Syntax ```markdown {{template:Infobox|title=MokoGitea|type=Software|license=MIT}} {{template:Warning|message=This page is under construction}} {{template:NavBox}} ``` ### Parameter Substitution Inside template files, parameters are referenced as `{{{title}}}`, `{{{message}}}`, etc.: ```markdown <!-- _Template/Warning.md --> > **Warning:** {{{message}}} ``` ### Implementation - **Pre-processor:** Before markdown rendering in `renderViewPage()`, scan the content for `{{template:...}}` patterns - **Resolve:** Load the template file from the wiki git repo, substitute parameters, and inline the result - **Recursive:** Templates can include other templates (with depth limit to prevent infinite loops) - **Cache:** Template content cached per wiki commit SHA ### Files to Modify | File | Change | |------|--------| | `routers/web/repo/wiki.go` | Template pre-processing step in `renderViewPage()` | | `services/wiki/wiki_template.go` | New — template resolution, parameter substitution | | `templates/repo/wiki/view.tmpl` | Hide `_Template/` pages from sidebar | ## Wikipedia Parity Wikipedia has over 60 million template transclusions. Templates are fundamental to maintaining consistent formatting, navigation boxes, infoboxes, and standardized notices across a wiki.
jmiller added the feature: wiki label 2026-06-21 06:34:10 +00:00
Sign in to join this conversation.