Getting the name of a Data type through .Properties?
Hello all!
This is my first post, so be gentle :).
I have been looking for a solution for quite a while now. I've been trying loop through all the properties on a page and create some HTML based on the generic properties that are added to the document template.
This returns both the name and alias. But i also want to get the data type name of the property, so that i can make an if statement (if the name of the property is == "Medlems bool", which is basically a true/false with a different name) - so i can get rid of properties i dont want to loop through.
Is what i am trying to do possible, does Umbraco even expose the data type names?
To get the datatype name you probably need to use an API that does db calls and I'm not if that's what you want. Can't you just check on the property alias and based on that skip it if you want?
I have also considered doing that. But the thing is at the moment i already have about 10 bools, and most likely more coming, it would have been a lot smoother if i could just check on the name :(
It doesnt help that they are placed in the same tab, right?
Do you by any chance have another suggestion / solution, it has to be easy to edit for the customer at the end :)
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
// ... other code omitted...
var ctService = ApplicationContext.Current.Services.ContentTypeService;
var dtService = ApplicationContext.Current.Services.DataTypeService;
var myType = ctService.GetContentType(Model.Content.DocumentTypeAlias);
var properties = myType.PropertyTypes.Select(x => new
{
x.Alias,
Type = dtService.GetDataTypeDefinitionById(x.DataTypeDefinitionId).Name
});
}
@foreach (var p in properties)
{
<div>
@p.Alias (@p.Type)
</div>
}
Like Jeroen says, this will be very, very slow. You should do some caching in static variables (with appropriate locking, of course) to avoid performance issues.
Getting the name of a Data type through .Properties?
Hello all!
This is my first post, so be gentle :).
I have been looking for a solution for quite a while now. I've been trying loop through all the properties on a page and create some HTML based on the generic properties that are added to the document template.
This returns both the name and alias. But i also want to get the data type name of the property, so that i can make an if statement (if the name of the property is == "Medlems bool", which is basically a true/false with a different name) - so i can get rid of properties i dont want to loop through.
Is what i am trying to do possible, does Umbraco even expose the data type names?
Hello,
To get the datatype name you probably need to use an API that does db calls and I'm not if that's what you want. Can't you just check on the property alias and based on that skip it if you want?
Jeroen
I have also considered doing that. But the thing is at the moment i already have about 10 bools, and most likely more coming, it would have been a lot smoother if i could just check on the name :(
It doesnt help that they are placed in the same tab, right?
Do you by any chance have another suggestion / solution, it has to be easy to edit for the customer at the end :)
This will do it:
Like Jeroen says, this will be very, very slow. You should do some caching in static variables (with appropriate locking, of course) to avoid performance issues.
is working on a reply...