KevinJump / uSync

Database syncing tool for Umbraco CMS
https://jumoo.co.uk/usync/
Mozilla Public License 2.0
109 stars 63 forks source link

v14 Template import is not working #666

Closed JoseMarcenaro closed 1 month ago

JoseMarcenaro commented 1 month ago

Describe the bug When adding a config file for a template: the Import action shows "Import" but it does not actually add the Template Both the [Report] button and the actual list of Templates show that it has not been imported.

To Reproduce Steps to reproduce the behavior:

  1. Create a new site from scratch using the Umbraco template - I used Umbraco.Templates::14.1.2
  2. Run the site for the first site, but when installing configure a SQL Local DB (not the default SQL Lite option)
  3. On Umbraco Settings, add a sample Template with the default content.
  4. Add the uSync nuget package - I used 14.0.1-preview001
  5. Run the site again. After startup, the uSync folder has been created and the uSync/v14/Templates folder contains the config for the created template => export works fine.
  6. In the uSync/v14/Templates folder duplicate the sample template config file with a new name. Edit this file to change the Template Key, Alias and Name
  7. In the Views folder duplicate the sample template cshtml file with a new name matching the alias you used in the config file.
  8. Exit the site (just in case) and run Umbraco again. Go to uSync and run [Report] - the new template shows up as pending for import
  9. Run [Import] => the template shows up as a successfull "Import" with "Details" (different Key!)
  10. Run [Report] again => the template is still pending for import
  11. Reload the Templates folder in settings => only the previously existing template shows up.
  12. Repeat steps 9-10-11 (same results)

Expected behavior The Umbraco Template for the new .config and razor file should have been created

About your Site (please complete the following information):

JoseMarcenaro commented 1 month ago

Oops - my mistake. The .cshtml for the new template was not a copy of the existing one and was not correct (referenced an invalid Layout) Once fixed the template, the import went fine.

JoseMarcenaro commented 1 month ago

Just to clarify what happened with my "invalid" razor view - in case someone else experiments the same problem.

In Umbraco v14, when saving a Template (Create or Update) the razor view content is parsed to lookup for the Layout assigment, i.e. Layout = null (default) or Layout = "myDefaultLayout.cshtml";

The Layout found is then set by Umbraco as the "Master Template" for the current one, and the current item is nested under the detected Layout ... that should be recognizable as another Template - in Umbraco v14. This is a new restriction in v14

So the template might be invalid - and unable to save - for several reasons:

Of course, this is an Umbraco restriction - not a uSync restriction So when you try to add the "offending" template using uSync, the operation silently fails due to the reasons mentioned.