Copied to clipboard

Flag this post as spam?

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


  • Uros Sankovic 107 posts 134 karma points
    Nov 13, 2010 @ 19:02
    Uros Sankovic
    0

    Loop through tab properties

    Hi,

    Is there a way to loop through all the tab properties from Document types? I have a document type with a tag with properties. I want to add new properties later, if I need them. So I guess I can't do that manually, since i don't want to go to template to add new properties every time I add them in document types.Do I do that with XSLT?

    THX for your help.

     

    Uros

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Nov 14, 2010 @ 14:13
    Lee Kelleher
    2

    Hi Uros,

    If you must do this with XSLT, then take a look at the uComponents XSLT extension for CMS. There is one extension called "GetDocumentType":

    public static XPathNodeIterator GetDocumentType(int docTypeId, bool includeTabs, bool includePropertyTypes, bool includeAllowedTemplates)

    If you did a quick dump of the XML, like this:

    <xmp>
        <xsl:copy-of select="ucomponents.cms:GetDocumentType(1047, 1, 1, 0)"/>
    </xmp>

    ... then you'd have the following XML:

    <DocumentType id="1047" name="Runway Textpage" alias="RunwayTextpage" image="default.png" thumbnail="doc.png" master="0" hasChildren="False" defaultTemplate="1045">
        <description>Runway textpage; this is the standard content page for a Runway website.</description>
        <tabs>
            <tab id="8" caption="Content" sortOrder="1"></tab>
        </tabs>
        <propertyTypes>
            <propertyType id="31" alias="bodyText" contentTypeId="1047" name="" mandatory="False" sortOrder="0" tabId="8" regEx="">
                <description></description>
            </propertyType>
            <propertyType id="32" alias="umbracoNaviHide" contentTypeId="1047" name="" mandatory="False" sortOrder="0" tabId="0" regEx="">
                <description></description>
            </propertyType>
        </propertyTypes>
    </DocumentType>

    ... then you could loop through all the <tab> nodes.  (OK, my XML example above only has one <tab> node! But you get the idea?)

    The corresponding <propertyType> node has an attribute for "tabId" ... so you'll need to do a little XPath mapping yourself.

    If you need a fuller example, let me know. Good luck!

    Cheers, Lee.

     

  • Uros Sankovic 107 posts 134 karma points
    Nov 14, 2010 @ 17:13
    Uros Sankovic
    0

    Hi, Lee,

    thx for your reply.You mentioned "If you must do this with XSLT...". Is there any other way so the new properties will be automatically added after I add them in DocumentType? THX again.

     

    Uros

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Nov 15, 2010 @ 11:18
    Lee Kelleher
    0

    Hi Uros,

    Some may find doing this in C# using the API much simplier, like so:

    var docType = umbraco.cms.businesslogic.web.DocumentType.GetByAlias("RunwayTextpage");
    if (docType != null)
    {
        foreach (var tab in docType.getVirtualTabs)
        {
            // tab.Id
            // tab.Caption
    
            foreach (var propertyType in tab.PropertyTypes)
            {
                // propertyType.Name
            }
        }
    }

     

    Cheers, Lee.

  • Rich Green 2246 posts 4008 karma points
    Nov 15, 2010 @ 11:35
    Rich Green
    0

    Hey Lee,

    Am I right in thinking both the XSLT and API will hit the database? 

    Rich

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Nov 15, 2010 @ 11:38
    Lee Kelleher
    0

    Hi Rich.

    Yes, both approached will hit the database, its unavoidable - not sure how many times though, depends on the number of tabs/properties.

    Cheers, Lee.

  • Rich Green 2246 posts 4008 karma points
    Nov 15, 2010 @ 11:45
    Rich Green
    1

    Uros,

    The only reason you have to hit the db is because you are retrieving the tabs.

    Instead you might want to consider prefixing the properties you want to appear automatically (auto_property1, auto_property2) and then you should be able to retrieve them in XSLT without hitting the db.

    Rich

     

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Nov 15, 2010 @ 11:49
    Lee Kelleher
    0

    Good point raised by Rich!

    If you only add new property-types infrequently, then I'd recommend using caching on your Macro ... keeps the flexibility of the code and saves it from hitting the database too often.

    Cheers, Lee.

Please Sign in or register to post replies

Write your reply to:

Draft