I want to build a generic macro to generate a table out of the properties of documents. I generated the following code that allows me to get the value of each property in the document:
But since that parsing of each property will depend on the data-type of the property, I need a way to query that, so I can then use a "choose" to parse the value correctly. (for example, if the data-type is an image upload, I have to include the "<img src=" and so on).
I've looked everywhere, and I can't find how to get the data-type of each property.
I don't think there is any way to do that using the standard xslt extensions. You would need to write some C# and use the API to fetch the current document type, and from there get the properties on that, and then get the datatype from there. This might be a bit database intensive, depending on how you are planning on using it? Will you be listing a lot of documents/properties at once, or is it more of a debugging feature?
I have not tested this, but I think this should do it:
using umbraco.cms.businesslogic.propertytype;
using umbraco.cms.businesslogic.web;
....
public static string GetDataTypeName(string documentTypeAlias, string propertyAlias)
{
DocumentType documentType = DocumentType.GetByAlias(documentTypeAlias);
PropertyType propertyType = documentType.getPropertyType(propertyAlias);
return propertyType.DataTypeDefinition.Text;
}
This should give you the text that you see on the datatypes in the tree in the Developer section. You can probably pretty easily change it to return something else, if you want, like the guid/int or whatever.
How to loop document properties
Hi,
I want to build a generic macro to generate a table out of the properties of documents. I generated the following code that allows me to get the value of each property in the document:
But since that parsing of each property will depend on the data-type of the property, I need a way to query that, so I can then use a "choose" to parse the value correctly. (for example, if the data-type is an image upload, I have to include the "<img src=" and so on).
I've looked everywhere, and I can't find how to get the data-type of each property.
Thanks
I don't think there is any way to do that using the standard xslt extensions. You would need to write some C# and use the API to fetch the current document type, and from there get the properties on that, and then get the datatype from there. This might be a bit database intensive, depending on how you are planning on using it? Will you be listing a lot of documents/properties at once, or is it more of a debugging feature?
Morten, thanks for your answer... do you have a sample of how the C# code could look like?
I have advanced a little further using just XSLT.
Now I can get the alias of the property by using
And the name of the property by using:
Now I could use some prefix in the alias to identify the type... but being able to get the data type would be so much better.
I have not tested this, but I think this should do it:
is working on a reply...