Detect Nesting Level

Duncan Koza asked on May 15, 2020 16:56

Hello,

I have a hierarchical transformation that has a maximum nesting level set to 2.

At the first level (0) it shows all the 'Folder PageTypes'. Then in the second level (1) it shows all the 'File Page Types' under each 'Folder Pagetype'.

The problem I am having is when a 'Folder PageType' is found at the second level. It gets displayed, but I don't want it to.

Is it possible to write something like this in my first level (0) transformation (text/xml):

if(nesting=1) {} else {my code}

I just don't know how to detect the nested level.

Recent Answers


Brenden Kehren answered on May 15, 2020 17:10

In your hierarichal transformation, you can specify which page types that particular transformation is for. So for instance on level 2 if you have multiple page types, you only create one transformation for that one page type you want to display.

0 votesVote for this answer Mark as a Correct answer

Duncan Koza answered on May 15, 2020 19:20 (last edited on May 15, 2020 19:27)

I am already doing that.

Since my hierarchical transformation is looking down two levels from where it is. It works fine if it finds a folder page type followed by a file page type.

But if the following scenario is true, I have troubles:

  • any other Page type that I don't care about (nesting level 1)
    • Folder Page Type (nesting level 2)
      • File Page Type (nesting level 3)

Since it is looking at only the first two nested levels. The hierarchical transformation seems to start at nesting level 2 because it didn't find anything at nesting level 1.

The thing is, If the hierarchical transformation doesn't find the folder until nesting level 2, then I don't want it. I only want to display page folders that are directly until it.

That's why I was thinking, if the hierarchical transformation does find it, maybe I can hide it with some code I poorly wrote above.

Basically... If my level 0 transformation runs at nesting level 2, I want to hide it. So, I think I need to add some code to my level 0 transformation.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on May 19, 2020 08:23

I think you may be misunderstanding what hierarchical data is. Level 0 is NOT the root of your website. Level 0 is wherever you tell the web part to get the data from so that could be / or it could be /About/Leadership or it could be /Events/North-America/Wisconsin.

If you want to get data below a specific area, you need to make sure you include that in your query BUT either leave the transformation out for that page type OR render some HTML tags for it.

My suggestion would be to include all the page types in your path, create a simple transformation that displays an unordered list inside an unordered list and display the page name and see what gets rendered. Complex hierarchical transformations are very difficult tondo but they are 100 times better than nested repeaters from a performance standpoint.

0 votesVote for this answer Mark as a Correct answer

Duncan Koza answered on May 19, 2020 16:00

Sorry, I sometimes struggle at explaining myself as I get used to using Kentico.

Here is an small example of my Site's tree.

  • Root
    • Section Page Type
      • Main Page Type
        • Folder Page Type
          • File Page Type
        • SubMain Page Type
          • Folder Page Type
            • File Page Type
          • Normal Page Type
            • Folder Page Type
              • File Page Type

I have a hierarchical transformation on Main Page Type, SubMain Page Type and Normal Page Type. The path is set to ./% for each one so it is my understanding that the path will start at each respective Page Type in the tree and the output seems to verify that. The Web part property of my Hierarchical viewer has it's Maximum nesting level set to 2.

On level 0 of my hierarchical transformation, I specify only the Folder Page Type and on level 1 of my hierarchical transformation, I specify only the File Page Type.

Everything seems to work in all areas of my tree. The scenario that is giving me grief is if Main page type doesn't have a Folder 'directly' under it, but SubMain Page Type does. Same with if SubMain Page Type doesn't have a Folder 'directly under it, but Normal Page Type does.

Example (I've only highlighted the Hierarchical transformation on my Main Page Type for this example):

  • Root
    • Section Page Type
      • Main Page Type <-- Hierarchical transformation web part is here
        • SubMain Page Type
          • Folder Page Type <-- The Level 0 hierarchical transformation seems to run here, but only when there is no Folder Page Type directly under the Main Page Type. My Level 1 hierarchical transformation doesn't get a chance to run because at this point the web part has already reached it's Maximum nesting level of 2.
            • File Page Type
          • Normal Page Type
            • Folder Page Type
              • File Page Type

The only solution I could find was to remove the ability to add Folders and Files under the SubMain Page Type.

Alternatively, I was hoping I could just detect if my Level 0 hierarchical transformation was being run at the web parts maximum nesting level 2, if so I could hide it.

0 votesVote for this answer Mark as a Correct answer

Duncan Koza answered on May 19, 2020 17:21

Unless... There is a way to make a 'WHERE condition' in the Hierarchical viewer web part?

If first node is Folder Page Type ?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.