0
votes

I'm new to Umbraco, so this may not even be feasible. I've created my own Datatype using Archetype and want to be able to get an instance of that type on the page by type, not alias. I know that I can do the following:

model.Content.GetPropertyValue("myAlias")

But I want to know if it's feasible to get the property by the type. Something along the lines of:

model.Content.GetPropertiesByType("TypeName")

which would return a list of controls on the page of that type?

Is this feasible?

2
Do you want to retrieve content based on a specific document type?Anonymous
It's possible, but not exactly straight forward.Robert Foster

2 Answers

0
votes

It's possible, but not exactly straight forward.

Take a look at the available Umbraco Data Services - you'll need to retrieve the DataTypeDefinitions from the DataTypeService and retrieve the ContentType for the Model's IPublishedContent using the ContentTypeService.

Once you have these, you can match up the PropertyTypes on the ContentType with the retrieved DataTypeDefionitions based on the PropertyType's DataTypeDefinitionId.

The PropertyTypes have an Alias property which will match up with the Property Aliases on the Content itself.

0
votes

You can use the content service if you get the id of the datatype you trying to find the multiples of from the url when you edit/create the datatype.

   @foreach (var p in ApplicationContext.Current.Services.ContentService.GetById(Model.Content.Id).PropertyTypes.Where(p => p.DataTypeDefinitionId == -89))
        {
            <p>@p.DataTypeDefinitionId</p>
        }