Fix wiki template creation in immersive editor
What does this MR do and why?
This MR fixes an issue where new templates would be saves as normal pages in wiki when using immersive editor: #601697.
While normal wiki pages can have a title that is separate from the pages' path (it's also a filename in the background, since wiki is a git repo), templates cannot. In normal pages, the page path is normally auto-generated from the title. The path is stores as a filename, the title as Frontmatter on the page. If a page has no title, the page's title is just a de-sluggified version of the path.
In templates however, frontmatter is not used and the de-sluggified path is always used as the template title. Add to that that the fact that templates are identified as such by being placed under the templates/ directory, this has led to an unintentional flow in immersive editor:
User creates a template -> default path is something like templates/{add title here} -> enters a title -> path is generated from title -> path no longer starts with templates -> page is saved a s a normal page.
So this MR streamlines the handling of templates in wiki immersive editor:
- there are now two recognized paths to create a template:
- By clicking "New template" which opens the edit view at
/-/wiki/templates/<someUUID>?view=edit(the form recognises that it's a template by the URL (default way) - editing a normal page and updating its path to start with
templates/(bit obscure, but works, so I'll keep it)
- By clicking "New template" which opens the edit view at
- when editing a template using the default way, the
templates/prefix is added automatically when generating a path. - Auto-generated
untitled-…paths are recognized whether or not they sit undertemplates/. Editing an untitled template's title regenerates its path. - Templates omit frontmatter. When a template is inserted into a regular page, no YAML frontmatter block leaks into the page content. The title is stored as part of the path slug instead.
- Read-only path field for templates with explanatory help text ("The path is generated from the title and cannot be edited."). The "Generate path from title" toggle is hidden in template mode. Previously it would do the same, silently ignore the page title. Making the path read-only ensures there is only one input to manipulate.
- Since paths for templates are readonly, added a "Restore original path" affordance. If a user accidentally turns a regular page into a template by typing
templates/…in the path, an inline link button under the help text restores the path captured at mount time. Only shown when template mode was triggered by updating the path. - Submit button label. "Create template" / "Save template" replaces "Create page" / "Save changes" when editing a template.
- A new
WIKI_TEMPLATES_DIRconstant centralizes thetemplatesdirectory name. - The frontend spec table was expanded to cover the new template scenarios (existing templates with various path/title states, persisted templates, path-only template detection, parent-path placeholders). New describe blocks cover the submit button label and the restore-path button. The wiki templates documentation was updated to describe the new title/path relationship.
References
Fixes #601697
Screenshots or screen recordings
| Before | After |
|---|---|
![]() |
![]() |
![]() |
![]() |
How to set up and validate locally
How to set up and validate locally
- Enable the feature flag with
echo "Feature.enable(:wiki_immersive_editor)" | rails c - open or create a new wiki inside a project at Plan > Wiki
- Create or open a wiki page. Click on the vertical ellipsis and select Templates. Click "New Template".
- In the template edit mode:
- Verify the path field is read-only and shows the help text (click on the chevron down icon near the title)
- Verify the path updates as you type the title (with
templates/prefix). - Verify the submit button reads "Create template".
- Save the template, then edit it.
- Verify the submit button reads "Save template".
- Verify editing the title regenerates the path.
- Apply the template to a new regular page. (Edit a page, click on chevron down, select template)
- Verify no YAML frontmatter block is inserted into the page content.
- Edit a regular wiki page and manually change the path to start with
templates/.- Verify the form switches to template mode (read-only path, help text).
- Verify a Restore original path link appears under the help text.
- Click it and verify the path returns to its original value.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.



