Unable to use Templates across Multiple Sites
Parent Issue
No response
Problem Statement
This was discovered in a meeting with VOXX when trying to show them how to share templates across multiple sites. However, this would also impact other multi-tenant clients. Looking both at demo and Voxx’s instances (both on 24.11.11) we noticed we no longer have the “all sites” dropdown option when trying to select templates living on other sites.
Steps to Reproduce
For example, on demo we created a site “Pagecopycreatetest” and a “test” template If we go to the “demo” host and try to create a page, we do not have an option to select “all sites” and are restricted to using only templates on my current site.
Acceptance Criteria
There should be the ability to drop down and select templates across sites.
dotCMS Version
The ability to select templates across sites exists in the 24.04 LTS so this must be a recent issue.
Proposed Objective
Core Features
Proposed Priority
Priority 2 - Important
External Links... Slack Conversations, Support Tickets, Figma Designs, etc.
https://dotcms.slack.com/archives/C028Z3R2D/p1731608383050379
Assumptions & Initiation Needs
No response
Quality Assurance Notes & Workarounds
No response
Sub-Tasks & Estimates
No response
https://dotcms.freshdesk.com/a/tickets/28692 -> problem reported by another customer
@patrick-schweiger I'm not clear where you're expecting to see the selection.
Can you please give us clear steps to reproduce? Meaning:
- Open screen X.
- Click field Y and select option Z
- etc.
I have confirmed this issue, steps to reproduce
- Create a new site
- Select the new site and create a template into this new site
- Get back to the initial site (default for instance)
- try to create a page
- when selecting the template for the page you are able to see the system template and only the templates for the current host, the template created for the new site is not available.
I think we are going to need a quick UI mockup to fix this properly
the issue is here: https://github.com/dotCMS/core/blob/main/dotCMS/src/main/java/com/dotcms/rest/api/v1/template/TemplateResource.java#L140
Basically there is a fallback when the hostid is null, blank or 404, the fallback in these situations will retrieve always the current host.
Probably we can do two things:
- send a by pass such as hostId=all that retrieves all of the hosts
- if the host is null, means retrieves everything instead of retrieve the current host templates
For references the call may by the UI looks such as
https://demo.dotcms.com/api/v1/templates/?filter=&page=0&per_page=1000&orderby=&host=3ba99f0e8ab5778b6139c9c6a6b742b9
@wezell @john-thomas-dotcms @jdotcms we use to have the selector options like this
Which included the "All Sites" functionality.
What is happening?
We lost this feature/functionality in this PR: Issue 28563 - Removing template AJAX and JS dependencies (#28618).
The relevant code where this functionality was implemented can be found here: TemplateAjax.java (Deleted).
Class: TemplateAjax Function: fetchTemplates Code Snippet:
//...
Template t = new Template();
t.setOwner(user.getUserId());
t.setModUser(user.getUserId());
t.setInode("0");
t.setTitle("--- " + LanguageUtil.get(user, "All-Hosts") + " ---");
t.setIdentifier("0");
fullListTemplates.add(t);
totalTemplates.add(t);
countF = count - 1;
//...
Possible Steps fix:
- [ ] check if the
/api/v1/templatesendpoint can retrieve all templates regardless of the host - [ ] Update the
templateFetchParamswith the necessary params to achieve that. - [ ] Add an
All Siteslabel to the dropdown as @fmontes show here. (It was deleted with the file)
How the dropdown currently work
We now use the /api/v1/templates endpoint to fetch templates. However, I'm not sure if this endpoint can retrieve all templates regardless of the host.
File: template_custom_field.vtl#L183-L195 Code Snippet:
//...
const templateFetchParams = {
query: {
fullTitle: '*'
},
queryOptions: {},
start: 0,
count: 1000,
sort: [],
onComplete: onTemplateFetchComplete
};
templateStore.fetch(templateFetchParams);
//...
PRs:
- https://github.com/dotCMS/core/pull/31086
Note to QA
This video includes the expected behavior we lost:
https://github.com/user-attachments/assets/fecde4f0-9589-4b84-872d-f48b9e2a83ac
Passed IQA
Tested in dotcms/dotcms:trunk
https://github.com/user-attachments/assets/d8d73364-4f4e-4c4d-8fa7-10b737420bfa
Only for 24.12 LTS