Template Development Workflow

Last updated:2026-11-25

For template developers: the complete workflow from building a front-end template from scratch, to packaging and delivery, to the customer switching it with one click in the admin panel. Each step maps to a later chapter of this manual; expand them as needed.

Overview of the Full Workflow

Prepare the directory structure → Read the base template (21 page files) → Override the pages you want to change
   → Fetch data with tags (list / one / pagebar) → Handle multilingual and SEO
   → Reference assets (/templates/<template-name>/…) → Follow the image upload rules
   → Package as a self-contained folder → Customer puts it into templates/ and selects it in the admin → Saved and takes effect immediately

Step 1: Directory Structure (Folder Name = Template Name)

templates/
└── mytheme/                  ← Folder name = template name = tpl_path
    ├── index.html            ← Home page (.html files must be at the root level!)
    ├── header.html           ← Shared header
    ├── footer.html           ← Shared footer
    ├── news.html             ← Article list
    ├── news_detail.html      ← Article detail
    ├── products.html / product_detail.html
    ├── cases.html / case_detail.html
    ├── category.html         ← Category page
    ├── page_detail.html      ← Single page
    ├── about.html / contact.html / error.html / icons.html
    ├── css/  js/  images/    ← Subdirectories may only hold assets, not .html

Four Hard Constraints

# Constraint Consequence of Violation
1 All .html files must be at the root level of the template folder The system loads templates with ParseGlob(templates/<template-name>/*.html), which does not recurse into subdirectories; files placed in pages/ will not be loaded
2 At least one .html file must exist at the root level Otherwise the template will not appear in the admin dropdown (folders that only contain subdirectories are skipped automatically)
3 index and admin are reserved names templates/index/ is the base template and templates/admin/ is the admin UI; they cannot be used as template names
4 Assets must be referenced with the absolute path /templates/<template-name>/… Relative paths resolve incorrectly on multi-segment URLs such as detail pages

Step 2: Understand “Base Template + Override Layer”

At render time the system first loads the base template templates/index/, then overrides files with the same name using your template folder. So a template package does not need to include every page — pages you don’t provide automatically fall back to the base template.

What Your Package Contains Actual Rendering Result
index.html + header.html + footer.html Home page, header, and footer use yours; other pages use the base template (but with your header/footer)
All 21 page files Your template takes over completely
Only index.html Only the home page has your styling; other pages keep the base template’s appearance

The 21 Page Files Included in the Base Template (Overridable List)

index.html      header.html     footer.html     icons.html      news.html
news_detail.html  products.html  product_detail.html  cases.html  case_detail.html
category.html   page_detail.html  about.html    contact.html    error.html
tag.html        jobs.html       job_detail.html  search.html    languages.html
media_gallery.html

Recommendation: for a full delivery, override at least index.html, header.html, footer.html, and every list/detail page to avoid inconsistent styling.

Step 3: Data-Fetching Tags

Inside templates, read admin data via {{.FieldName}} and fetch data flexibly with functions such as list / one.

Need What to Use Corresponding Chapter
Query content with arbitrary conditions list Content List
Fetch a specific piece of content one Specific Content (one function)
Pagination bar pagebar Pagination Bar
Multi-value fields (multiple images / tags / multi-select) splitJSON Iterating Multiple Images / tags / Multi-select
Current category / specific category .CurrentCategory etc. Current Category / Specific Category
Navigation menu Site navigation data Navigation Menu
Carousel/banner Slideshow data Slideshow Carousel
Breadcrumbs Parent categories + current category Breadcrumb Special Demo
On-site full-text search Search page data On-site Full-text Search
Multilingual cross-links {{.LangSwitcher}} / {{.HrefLangs}} Multilingual Sites
Company / site info Company info / Site info Corresponding chapters
Friend links Friend link data Friend Links

Pipes and Common Functions

Purpose Syntax Description
Date formatting {{.CreatedAt \| formatDate "Y-m-d"}} Outputs the time per the given format
Content truncation {{.Summary \| truncate 50}} Truncates by character (rune), CJK-friendly, appends ... when truncated
Output HTML as-is {{.Content \| safeHTML}} Rich text is escaped by default; marked as safe HTML it renders as-is
Numeric operations {{add .CurrentPage 1}} Integer addition
JSON / multi-value splitting {{range splitJSON .Images}} Parses multiple images, tags, etc. into an iterable slice
Custom snippets {{.FooterNotice}} Admin “template content snippets” are injected as global variables of the same name (the name is defined by you in the admin)

Detail links must use {{.URL}} — it already carries the site prefix, which is required for correctness on multilingual subsites; hardcoding /news/{{.ID}} loses the language prefix.

URL Rules: Public Pages Are Always Path-Style, Without ?

Both the platform site’s and tenant sites’ front ends sit behind CDN / edge caches. The cache key typically only considers the path, so parameters like ?tag= / ?q= are dropped (symptom: “clicking a filter does nothing”). Therefore:

  • Platform public pages (template marketplace / docs / aggregation pages) use only path-style .html addresses; template marketplace category / tag / search URLs look like /templates/cat/<slug>.html, /templates/tag/<slug>.html, /templates/search/<token>.html.
  • Tenant site list pagination uses path-style fields such as FirstURL / PageNumbers[].URL / NextURL; do not use ?page=N generated by pagebar / pageURL.
  • Always use {{.URL}} for detail links, never hardcoded paths; platform sites standardize on url_detail_nest=flat + url_detail_suffix=.html.
  • Keep exactly one address per piece of content: new platform sites do not 301 old links; forms without .html return 404.

Step 4: Asset References

css/js/images inside the template folder are served via a dedicated static route with the URL rule /templates/<template-name>/<relative-path>:

<link rel="stylesheet" href="/templates/mytheme/css/style.css">
<script src="/templates/mytheme/js/main.js"></script>
<img src="/templates/mytheme/images/logo.png" alt="logo">

Site-wide shared /static/… is also supported. Self-contained templates are recommended to use /templates/<template-name>/ exclusively, so the whole folder can be copied and reused.

Allowed Asset Extensions (Referencable from the Front End)

Category Extensions
Styles / scripts .css .js .mjs
Images .png .jpg .jpeg .gif .svg .webp .bmp .ico .avif
Fonts .woff .woff2 .ttf .eot .otf
Audio / video .mp4 .webm .ogg .mp3 .wav
Data / documents .json .xml .txt .csv .pdf

.html and any extension outside the whitelist return 403 when accessed by URL, so template source cannot be downloaded; ../ path traversal is blocked as well. Therefore it is safe to place .html files and assets in the same folder.

Step 5: Image Upload Rules

The admin “upload image” feature is stricter than front-end asset references and only allows .jpg .jpeg .png .gif .webp .avif:

  • .svg (XSS risk) and .bmp have been removed from the upload whitelist and cannot be uploaded via the admin (but can still be placed manually as static assets and referenced);
  • Uploaded images are automatically compressed and converted to AVIF in the browser (WebP if AVIF is unsupported) before submission;
  • The server performs real type validation as a fallback and does not trust the extension.

For the full mechanism, see “Admin Image Upload: Security Validation and Automatic AVIF Conversion”.

Step 6: Multilingual and SEO

  • Multilingual means “one language = one site”; path prefixes (e.g. /en) are automatically stripped and handled by the site resolver;
  • When bulk-creating sites via “Site Management → One-click Enable Language Sites”, each language site receives a complete copy of the Chinese site’s current template (for multi-tenant it lands in <tenant-dir>/templates/<language-code>/); the language templates do not affect each other; hardcoded Chinese copy in templates still needs to be adjusted per language;
  • Language switcher: {{.LangSwitcher}}; hreflang cross-links: {{.HrefLangs}};
  • SEO head variables to wire up: {{.PageTitle}} / {{.PageKeywords}} / {{.PageDescription}}, plus canonical, og, and JSON-LD related variables;
  • Detail pages automatically output Article / Product JSON-LD and BreadcrumbList.
⚠️ 注意

Whether multilingual tags output depends on whether the current site has multilingual capability: under SaaS this is determined by the platform per plan/subscription; in the standalone delivery edition it is determined by the license code. See the scope note at the beginning of “License and Email Services”.

Step 7: Packaging and Delivery

Role What to Do
Template developer (you) Build a complete template with all files in one folder and deliver that folder
Deployment / ops Place the entire folder under templates/ in the program directory
Customer Select it in the admin under “Site Info → Template Path” dropdown → Save. Takes effect immediately

Multilingual sites may each select a different template: every site (including subsites) sets its own template path independently in “Site Management”. Language sites created via “One-click Enable Language Sites” get a copy of the Chinese site’s template; modifying that copy affects only that language, not other languages or the shared template.

Step 8: Installation and Switching

Step Action
1 Copy the entire template folder into templates/ in the program directory
2 Admin → “Site Info” → “Template Path” dropdown, select it
3 Click Save. The system automatically reloads templates, no process restart needed
4 Refresh the front end to see the result (if page caching is enabled, wait about 1 minute or clear the cache in the admin)

Step 9: Admin Extensions and Operations (Template Developers Should Know This Too)

Templates ultimately run on the CMS; these admin capabilities directly affect front-end output:

Capability Entry / Description
External event Webhook Content create/update/delete pushed to external systems; enabled by configuring CMS_WEBHOOK_URLS + CMS_WEBHOOK_EVENTS
Hook bus In-process event bus (internal/hooks), supports registering custom hooks and custom routes
Custom template functions Register in GetTemplateFuncs to make them available in templates (template calls to unregistered function names are not possible)
Media library /admin/media, lists all files in static/uploads/, supports rename / delete / unused-file cleanup
Backup and restore /admin/backup, JSON export/import + full SQLite database snapshot
Audit log /admin/audit, records logins, content CRUD, media deletion, backup/restore
Batch add / delete All five content types support batch add (including “quick import”) and batch delete
Translation status check /admin/i18n, lists missing or empty-title items pending translation for target sites
Static space publishing /admin/deploy, 8 space types + splitting by file category + connectivity testing
Configuration parameters /admin/config, 8 groups; among them URL rules / title styles directly determine {{.URL}} and {{.PageTitle}}. Public pages are always path-style + .html with no ?; tenant detail pages recommend url_detail_nest=flat + url_detail_suffix=.html (canonical address /<segment>/<id>.html)
WebAPI External read-only JSON API (GET only, returns published content only), switch and token in configuration parameters
Search engine proactive push Baidu API / IndexNow, with optional “auto push after save”
Security configuration Login failure lockout, admin IP whitelist, session policy, upload blacklist
System update /admin/system-update, runtime info + clear logs / compact database

Step 10: Pre-Delivery Checklist

Check Standard
All .html at the folder root No .html in subdirectories
All assets use absolute paths Search once to confirm no relative patterns like href="css/ or src="images/
Template name matches asset paths If the folder is named mytheme, references must be /templates/mytheme/…
Detail links use {{.URL}} No hardcoded /news/{{.ID}} etc.
No ? links Pagination uses path-style fields, details use {{.URL}}; no hardcoded ?page= / ?tag=
SEO variables wired up {{.PageTitle}} / {{.PageKeywords}} / {{.PageDescription}}
Header/footer reused Use {{template "header.html" .}} instead of copy-pasting across pages
No extraneous large files Remove design drafts, .psd, node_modules, etc. (they cannot be served anyway)

Troubleshooting

Symptom Cause and Solution
My template doesn’t appear in the dropdown No .html at root level; or a reserved name index / admin was used; or it was not placed under templates/ in the program directory
Template selected but pages unchanged .html files were put into subdirectories (not loaded); or file names don’t match the base template so no override happened; or page cache hasn’t expired
Structure is right but no styles, images broken Wrong asset paths. Must be /templates/<template-name>/css/style.css; relative paths are not allowed, and the leading / must not be omitted
An asset returns 403 Extension not in the whitelist (in particular, accessing .html directly is intentionally prohibited)
An asset returns 404 URL path doesn’t match the actual disk path (mind case sensitivity); or the file genuinely doesn’t exist
Multilingual subsite links lost the language prefix Detail links were hardcoded as /news/{{.ID}}; must switch to {{.URL}}
Changed .html but the front end still shows the old version Templates are loaded at startup / when saving a site. After changing files, re-save the site info once in the admin to trigger a reload

Related docs: CMS Admin Workflow · Static Site Publishing · Multilingual Sites

This site uses cookies for essential functionality and to improve your experience. See our Privacy Policy.