Templates
uSync stores templates as .config files in the Templates folder. By default the file holds the template's name, alias, key and parent template, but not the Razor code itself. When uSync creates a template on import, it gets the template's content from the view file on disk.
This page applies to uSync 17.4.0 and later. Earlier versions behave differently when a view file is missing; see what changed in 17.4.
Where the Template Content Comes From​
When uSync creates a template that doesn't exist on the site yet, it looks for the content in this order:
- The uSync file. If the
.configfile contains the template's content (aContentselement), uSync uses it. This doesn't apply when views are compiled into the site. - Umbraco's template service. uSync asks Umbraco for the view file, the same way Umbraco loads it. The file is
Views/{alias}.cshtml. - The views folder. If the template service has nothing, uSync reads
{alias}.cshtmlfrom the site's views file system. - A placeholder. If the content is still missing and views are compiled into the site, uSync creates the template with a placeholder.
If none of these work, the import of that template fails with a warning that the local file is missing.
When the template already exists, uSync updates its name, alias and parent, and only changes the content if the uSync file contains it. The view file on disk is left as it is.
View File Names​
The view file name is the template alias exactly as it is, plus .cshtml. uSync no longer strips spaces from the alias, so it looks for the same file Umbraco does. For example, A template with the alias my Page uses Views/my Page.cshtml.
Missing View Files​
If uSync needs to create a template, the view file isn't on disk, and views aren't compiled, the import fails for that template. The uSync report shows an error saying the template file is missing, and the log has a warning:
Failed to create template {alias}.cshtml the local file is missing
Make sure the .cshtml files are deployed with the uSync folder, or include the template content in the uSync files.
Production Mode​
When Umbraco runs in Production runtime mode, views are compiled into the site and there are no .cshtml files on disk. You can also tell uSync that views are compiled with the UsingRazorViews handler setting:
"uSync" : {
"Sets" : {
"Default" : {
"Handlers" : {
"TemplateHandler" : {
"Settings" : {
"UsingRazorViews" : true
}
}
}
}
}
}
When views are compiled:
-
uSync will ignore any template content in the uSync files, because the compiled view is used.
-
If a template's content can't be found, uSync will create the template with a placeholder. The placeholder is a small Razor block that sets the layout to the parent template:
@{Layout = "master.cshtml";}Umbraco reads the
Layoutvalue to work out a template's parent, so the parent/child relationship in the backoffice is kept. -
At the end of the import, uSync deletes any placeholder
.cshtmlfile it wrote, so it doesn't replace the compiled view.
What Changed in 17.4​
uSync 17.4.0 (uSync#1059) changed how template content is found:
- Missing view files now fail the import. Before 17.4, a bug meant the fallback steps never ran, so a template whose view file was missing was imported as an empty template with no warning. Now uSync tries each step above and reports the missing file. If you relied on the old behaviour, check your deployments include the
.cshtmlfiles. - The placeholder sets the parent template. The old placeholder for compiled views wasn't valid Razor, so Umbraco couldn't read the parent template from it and the relationship was lost. The placeholder now sets
Layout, so the parent is kept. - View file names match Umbraco. uSync used to strip spaces from the alias when building the view path. It now uses the alias as it is, like Umbraco.