Is there a way to add a Umbraco Custom Data Type t

2020-07-06 03:37发布

问题:

On a number of different document types, I have to add the same 3 native Umbraco data types

  1. content picker
  2. TextString
  3. TextString

It was suggested to me to see if there is a way to create a new custom data type that would basically wrap those 3 datatypes into a new datatype.

I looked at nibble.be's site and see there is a couple different ways to go about creating custom data types (using the usercontrol wrapper, or 3 class approach). However, I am not sure that a custom data type for grouping existing datatypes would be the correct route.

For one thing, we are using MVC along side Umbraco with a heavy use of Razor views. Since the document type property alias is used to acquire values from Umbraco from the content page, I don't see how this would still be possible or how you would go about getting the property value of a custom datatype that has embedded datatypes.

Would there be a working way or a better way to accomplish this solution for having to add the same fields on any document type that they are needed? I though about hierarchical approach with a document type parent with only these 3 data types (content picker and 2 textstrings), but that would mean having to put any document type that a page would need under this parent document type simply for the fact to inherit these group of properties.

回答1:

If you're looking to embed multiple properties into a single datatype:

There are a number of embedded datatypes available; DataType Grid, Embedded Content, and Repeatable Custom Content are the three I know of. All three store their information as xml which allows easy access via both xslt and razor.

The DataType Grid is part of uComponents and is therefore actively developed. It is also open source and therefore contributions are encouraged. Embedded Content and Repeatable Custom Content, while still useful, don't appear to have any current support and therefore no plans for improvement. I think they are licensed as open source, but the source isn't publicly available as far as I can tell.

I don't think you can set a limit on the number of rows/items stored in the DataType Grid, like you can in Embedded Content (perhaps a feature request).

Take a look at some of these solutions before you plan on rolling your own. But if you still feel the urge to code out your own data type, I'd recommend Tim Geyssens' articles on created custom datatypes using the user control wrapper, with data editor settings, and serializing the data as xml. His "Master of Datatypes" video is also really helpful and covers those topics as well.

If you're looking to organize your properties into groups:

Tom Fulton published a new package/data type recently called Document Type Fieldsets that may fit your needs. It allows you to group fields together in a fieldset. Here's a screen shot:



回答2:

I realize this is an old question, so I'm just adding this for anyone searching for this functionality in the future: This is almost exactly what we use Widget Builder for in Umbraco 6.

Widget Builder is the predecessor to Umbraco 7's Archetype which is being pushed by the core team for near universal use. I believe it's going to become a part of the core.

Internally, WidgetBuilder and Archetype store their data as JSON and make it very easy to copy a custom data type from one project to another with an import/export feature.



回答3:

I used to work with Archetype for some time until I discovered Nested Content which does the same thing but much easier to work with because it nests Document Types instead of Data Types which is much easier to work with, especially for Content Editors. Plus the resulting Data Types is normal built-in Umbraco ones, not Archetype Objects which add a new layer of Entity Mapping in your views.



标签: umbraco