you should beable to do this via the FileService that is the new API to manage stylesheets and templates, but i think the seceret truth might be that you have to do it with the legacy API - because it looks like that's what the Umbraco back office is doing.
tracing through from the template dialog, it looks like the save function for the template fires SaveTemplate in CodeEditorSave webservice.
Now that uses the old api too, but this might be a good starting point - because without relying to much on old code, you might be able to call this reset service ( so do a HTTP post to /Umbraco/RestServices/SaveFile/SaveTemplate ).
unlike the new api - you don't run things through the service controller, so you just get a copy of your template by ID, and change Text (which is the old name for Name) and do template.Save();
so the short answer might be:
// using umbraco.cms.businesslogic.template
var t = new template(id);
t.Text = "NewName" ;
t.Save();
I haven't tried this, i don't know if you have to rename the physical file or if Umbraco will do it for you.
and all this code is obsolete at some point & it might be worth throwing something into issues.umbraco.org - saying FileService offers no way to rename templates.
How do I rename a template programatically
I wish to change a template named Home to Homepage programatically for a migration script.
I tried
but I get the compile error:
In this case I don't want to rename any files, my Homepage.cshtml will already exist.
Cheers.
Murray
I think to do that you must use contentservice as other methods access cache not the database.
Hi
you should beable to do this via the FileService that is the new API to manage stylesheets and templates, but i think the seceret truth might be that you have to do it with the legacy API - because it looks like that's what the Umbraco back office is doing.
tracing through from the template dialog, it looks like the save function for the template fires SaveTemplate in CodeEditorSave webservice.
https://github.com/umbraco/Umbraco-CMS/blob/dev-v7/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/codeEditorSave.asmx.cs#L436
which itself is using the old api - but say's its obsoleated by SaveTemplate in the FileSaveController
https://github.com/umbraco/Umbraco-CMS/blob/ded1def8e2e7ea1a4fd0f849cc7a3f1f97cd8242/src/Umbraco.Web/WebServices/SaveFileController.cs#L164
Now that uses the old api too, but this might be a good starting point - because without relying to much on old code, you might be able to call this reset service ( so do a HTTP post to /Umbraco/RestServices/SaveFile/SaveTemplate ).
if that's to fiddly - i think you have to resort to the old api (pre v6/7) stuff, which is in https://github.com/umbraco/Umbraco-CMS/blob/dev-v7/src/umbraco.cms/businesslogic/template/Template.cs
unlike the new api - you don't run things through the service controller, so you just get a copy of your template by ID, and change Text (which is the old name for Name) and do template.Save();
so the short answer might be:
I haven't tried this, i don't know if you have to rename the physical file or if Umbraco will do it for you.
and all this code is obsolete at some point & it might be worth throwing something into issues.umbraco.org - saying FileService offers no way to rename templates.
Yep thanks. slightly tweaked solution (fix capitalisation, and set Alias):
added issue: http://issues.umbraco.org/issue/U4-6381
is working on a reply...