U4-2793 - There doesn't seem to be a way to un-assign a template from a content item with the new API

Created by Shannon Deminick 05 Sep 2013, 05:13:36 Updated by Shannon Deminick 05 Aug 2015, 14:30:23

Is duplicated by: U4-301

Is duplicated by: U4-4749

Relates to: U4-3562

Subtask of: U4-5830

If I set the contentItem.Template = null and it already has a template assigned I would expect it to clear the assigned template but this is not the case.

(unless I'm doing it wrong)

Comments

Sebastiaan Janssen 05 Sep 2013, 06:16:14

I can do it through the interface (doctype has a template at first, publish page, then edit doctype to not allow templates, publish item again, template is gone) so there must be a way. :)


Shannon Deminick 05 Sep 2013, 06:18:48

Hrm, might be an issue with the ShouldCreateNewVersion method or something, maybe it's not checking for a template change. For example, what happens if you have your page published, then change the template and publish again ? does the template update ?


Sebastiaan Janssen 05 Sep 2013, 06:33:32

Yup!


Shannon Deminick 05 Sep 2013, 06:46:52

all using the new API ?


Sebastiaan Janssen 05 Sep 2013, 06:49:22

Hehe, good question. I'm reporting from the frontend side of things, haven't looked at the code. ;-)


Morten Christensen 05 Sep 2013, 06:51:16

If you set .Template on Content to null it will use the default template from the ContentType. So could very well be an oversight in the new API ... Not sure what the backoffice does (does anyone? :))

I don't think there's a RemoveTemplate method on the ContentService, but guess there should be one on the Content class.


Morten Christensen 05 Sep 2013, 08:50:41

Okay, so the legacy Document class has a RemoveTemplate method, which sets the Document.Template to 0 (zero - its just an integer). And the Template property just does the following: [Obsolete("Obsolete, Use Template property on Umbraco.Core.Models.Content", false)] public int Template { get { return _template; } set { _template = value; if (value == 0) else } }

So it does actually just set the Content.Template to null.


Morten Christensen 05 Sep 2013, 09:10:09

After testing through the backoffice its not currently possible to remove a template. If the document type has a default template it will always fallback to that template. And it also looks like its not possible to not have a default template on a document type as it uses the first one selected in the list of allowed templates.


Morten Christensen 05 Sep 2013, 09:16:27

Update: It has never been possible to un-assign a template from Content: http://issues.umbraco.org/issue/U4-301 The only way to have Content without a template is to remove the template from the Document Type.


Morten Christensen 05 Sep 2013, 09:52:02

Update 2: The ContentType should be able to not have a default template. So in the backoffice when selecting an allowed template it currently autofills it as the Default template, but it should be possible to save that Document Type without a default template. When you have a Document Type without a default template you can create content without a template, but once a template has been selected on that content you cannot un-assign it. (Verified in v.4.11.5)


Priority: Normal

Type: Bug

State: Fixed

Assignee: Shannon Deminick

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted:

Affected versions: 6.0.0, 6.1.0, 6.0.1, 6.0.2, 6.0.3, 6.0.4, 6.1.1, 6.0.6, 6.0.5, 6.0.7, 6.1.3, 6.1.4, 6.1.5

Due in version: 7.3.0

Sprint:

Story Points:

Cycle: