Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Fernando 9 posts 30 karma points
    Nov 07, 2010 @ 06:25
    Fernando
    0

    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:

    <xsl:for-each select="$currentPage/* [not(@isDoc)]">
    <xsl:value-of select="."/>
    </xsl:for-each>

    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

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Nov 07, 2010 @ 11:06
    Morten Bock
    0

    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?

  • Fernando 9 posts 30 karma points
    Nov 07, 2010 @ 15:30
    Fernando
    0

    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

    <xsl:value-of select="name(.)"/>

    And the name of the property by using:

    <xsl:value-of select="umbraco.library:GetPropertyTypeName(name($currentPage),name(.))"/>

    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.

     

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Nov 07, 2010 @ 16:02
    Morten Bock
    0

    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.
Please Sign in or register to post replies

Write your reply to:

Draft