I posted in this forum a little while ago about the options available to developers to work with the Umbraco back-end programmatically. Since then I've been cracking on with using the API and have successfully created a document type using this snippet:
umbraco.BusinessLogic.User user = new umbraco.BusinessLogic.User("admin");
DocumentType dt = DocumentType.MakeNew(user, "Test Template"); dt.Description = "Test template description"; dt.Alias = "testTemplate"; dt.Save();
I then went on to flesh out my document type with a new property (as you would in the web interface by going to "Generic Properties" and creating a new property manually. This was less straightforward as I couldn't find any good examples, and the API documentation for the PropertyType class usefully says "Summary description for propertytype"! But I've managed to piece together something that seems to work in order to create a boolean property on my new document type:
The thing I'm wondering now is how would I add this property to a custom tab. For example, I know also that I can create a custom tab on the document type using:
dt.AddVirtualTab("My custom tab"); dt.Save();
But it's specifying that the new property I'm creating is to belong to this new tab that's causing me bother. Can anyone fill me in on how to do this?
Creating a document type property programatically
Hi all,
I posted in this forum a little while ago about the options available to developers to work with the Umbraco back-end programmatically. Since then I've been cracking on with using the API and have successfully created a document type using this snippet:
I then went on to flesh out my document type with a new property (as you would in the web interface by going to "Generic Properties" and creating a new property manually. This was less straightforward as I couldn't find any good examples, and the API documentation for the PropertyType class usefully says "Summary description for propertytype"! But I've managed to piece together something that seems to work in order to create a boolean property on my new document type:
The thing I'm wondering now is how would I add this property to a custom tab. For example, I know also that I can create a custom tab on the document type using:
But it's specifying that the new property I'm creating is to belong to this new tab that's causing me bother. Can anyone fill me in on how to do this?
Hi Matt,
I think you should be able to do the following:
Matt
That's done it, thanks Matt.
How did you guys manage to get it working? I keep getting:
Method not found: 'Void umbraco.cms.businesslogic.ContentType.AddPropertyType(umbraco.cms.businesslogic.datatype.DataTypeDefinition, System.String, System.String)'.
I'm using Umbraco 4.7.1.
@donatas the method no longer returns null
In the older version of Umbraco the method's return type was
public void AddPropertyType
whereas the new onepublic PropertyType AddPropertyType
So the final code(assuming correct assemblies are referenced):
Thanks Rob, in the end I got it working. BTW that's my post on stackoverflow :)
In case anyone stumbles on this question and is using Umbraco 8, I have written how to create custom properties for members here https://our.umbraco.com/forum/extending-umbraco-and-using-the-api/78210-add-custom-property-to-membership-member#comment-335629
is working on a reply...