Finding how many levels deep an asset is

Hi All,


does anyone know of a way to query for the depth of an asset (in terms of site hierarchy) with a keyword or similar?



I'd like to show a Design area only if the asset is below a certain depth.



The (IMO clunky) way would be to assign metadata to the assets that are the required depth, and match on that. But I'm wondering if there is a nicer way.



Any ideas?



Steve

[list=1]

  • Nest the asset listing page in the design area[]set the asset listing page dynamic root, look up the tree for a link value, set the min depth as you like[]set the link value of the uppper level page, store the content in its metadata field (do not display in frontend)[*]apply the design customisation to the pages.On the page which is deep enough, the nested asset listing page finds the uppper level page and print the content from its metadata; on the page which is not deep enough, as the upper level page is outside of the range of minimum depth, the asset listing page finds nothing.
  • [quote]
    [list=1]

  • Nest the asset listing page in the design area[]set the asset listing page dynamic root, look up the tree for a link value, set the min depth as you like[]set the link value of the uppper level page, store the content in its metadata field (do not display in frontend)[*]apply the design customisation to the pages.On the page which is deep enough, the nested asset listing page finds the uppper level page and print the content from its metadata; on the page which is not deep enough, as the upper level page is outside of the range of minimum depth, the asset listing page finds nothing.

    [/quote]



    Robin, thanks for taking the time to reply.



    I probably should have been more specific in the OP, sorry.



    Your solution would be nice if it is content attached to the assets which I need to show conditionally on the asset depth, but it is more difficult:



    Assuming the following site structure
        
        Site
          Home page
        page 1
          page 1.1
            page 1.1.1
          page 1.2
            page 1.2.1
        Sub page 2
          page 2.1
            page 2.1.1
          page 2.2
            page 2.2.1
        Sub page 3
          page 3.1
            page 3.1.1
          page 3.2
            page 3.2.1
    


    I have 2 different kinds of nav I'd like to show depending on the asset depth. One kind on the home page, it's children and grandchildren (i.e. home page, sub page [1-3] and pages 1.1 - 3.2). And the other kind on the pages below these (i.e. pages 1.1.1 - 3.2.1).

    Because it is navigation and I need to show which page is current (without client-side scripting) I have to use a menu_normal design area, please correct me if this is wrong.

    My proposed solution is to have the 2 kinds of nav in the parse file and hide/show the correct nav dependent on the level (using a show_if). So the question is how can I dynamically feed the asset level to the design. Applying metadata to the assets below a certain level would do the trick but would be an ongoing maintenance problem when new pages and structures are created by our editors.

    I had thought that something like this might work:
        
           
    
     <MySource_SET name="prefix_with_home_link" value="false" />
     <MySource_SET name="suffix_with_current_link" value="false" />
     <MySource_SET name="prefix_with_divider" value="false" />
     <MySource_SET name="suffix_with_divider" value="false" />
    
     <MySource_SET name="levels_to_print" value="1" />
     <MySource_SET name="start_at_level" value="1" />
    
     <MySource_DIVIDER></MySource_DIVIDER>
    
     <MySource_ASSET>IAMLEVEL1</MySource_ASSET>
    
       </MySource_AREA>
       <MySource_AREA id_name="level2" design_area="asset_lineage" print="no">
    
     <MySource_SET name="prefix_with_home_link" value="false" />
     <MySource_SET name="suffix_with_current_link" value="false" />
     <MySource_SET name="prefix_with_divider" value="false" />
     <MySource_SET name="suffix_with_divider" value="false" />
    
     <MySource_SET name="levels_to_print" value="1" />
     <MySource_SET name="start_at_level" value="2" />
    
     <MySource_DIVIDER></MySource_DIVIDER>
    
     <MySource_ASSET>IAMLEVEL2</MySource_ASSET>
    
       </MySource_AREA>
       <MySource_AREA id_name="level3" design_area="asset_lineage" print="no">
    
     <MySource_SET name="prefix_with_home_link" value="false" />
     <MySource_SET name="suffix_with_current_link" value="false" />
     <MySource_SET name="prefix_with_divider" value="false" />
     <MySource_SET name="suffix_with_divider" value="false" />
    
     <MySource_SET name="levels_to_print" value="1" />
     <MySource_SET name="start_at_level" value="3" />
    
     <MySource_DIVIDER></MySource_DIVIDER>
    
     <MySource_ASSET>IAMLEVEL3</MySource_ASSET>
    
       </MySource_AREA>
    
    <MySource_AREA id_name="levels" design_area="declared_vars" print="no">
    <MySource_DECLARE name="level1" value="<MySource_PRINT id_name="level1" />" type="text" description="is this asset below level 1?" />
    <MySource_DECLARE name="level2" value="<MySource_PRINT id_name="level2" />" type="text" description="is this asset below level 2?" />
    <MySource_DECLARE name="level3" value="<MySource_PRINT id_name="level3" />" type="text" description="is this asset below level 3?" />
    </MySource_AREA>
    




    But it looks like you can't use a MySource_PRINT in that context, and I'm not sure I can get access to the declared vars outside the

    parse file to set up the pattern matching in the customisation.



    Is there another way to query the asset for it's depth?



    I hope this makes it clearer.



    Thanks



    Steve
  • Steve there are several ways to get there but depending on how different the page's layouts are for upper level(home page, sub page [1-3] and pages 1.1 - 3.2) and lower level(pages 1.1.1 - 3.2.1).
    If they are quite different, you will need to set up separate parse file for each. As the editors create pages and structures, they need to bear in mind how to apply the design on the page depending on the structure. Setting up a trigger may help them.

    If only the navigation is different, you can go on with the current way (a single parse file with condition). You will use <show_if> design area but there is no such condition for the page depth. I suggest you consider using asset type condition. In this case home page, sub page [1-3] and pages 1.1 - 3.2 will be the asset whose type is other than pages 1.1.1 - 3.2.1's.

    Other guys here may have the better ideas.

    [quote]
    Steve there are several ways to get there but depending on how different the page's layouts are for upper level(home page, sub page [1-3] and pages 1.1 - 3.2) and lower level(pages 1.1.1 - 3.2.1).

    If they are quite different, you will need to set up separate parse file for each. As the editors create pages and structures, they need to bear in mind how to apply the design on the page depending on the structure. Setting up a trigger may help them.

    If only the navigation is different, you can go on with the current way (a single parse file with condition). You will use <show_if> design area but there is no such condition for the page depth. I suggest you consider using asset type condition. In this case home page, sub page [1-3] and pages 1.1 - 3.2 will be the asset whose type is other than pages 1.1.1 - 3.2.1's.

    Other guys here may have the better ideas.

    [/quote]



    Robin,



    The only difference will be the nav shown. So I think I will stick to the single parse file.



    I'm not sure I understand how I can use an asset type condition to choose which nav to show, as all my pages in the above structure are of type standard_page.



    Did you mean something else by this?



    Steve

    Steve,


    I mean use asset of "folder", for example, for the pages of "home page, sub page [1-3] and pages 1.1 - 3.2) and lower level(pages 1.1.1 - 3.2.1"then put the page content in folder's metadata. In this way show_if can tell the current page's asset type and give the appropriate nav.



    Robin

    The only solution I could think of that would work for this (without client side scripting), would be to output a css class in a lineage. I'll try to give an example, but this isn't tested - only an idea:

        
        
        #menu .exampleexampleexample { display: none; }
        #menu_from_3rd_level { display: none; }
        #menu_from_3rd_level .exampleexampleexample  { display: block; }
        
    



        
        
        
        
        
        
        
        
        
        
        
        
        example
        
        
        
    ">
    ">


    The idea being that the css class 'exampleexampleexample' would only ever be applied when the lineage is 3 or more levels deep. The menus you configure to show can be set to start from 3 levels deep too, if that's what you need it to do.

    [quote]
    The only solution I could think of that would work for this (without client side scripting), would be to output a css class in a lineage.

    [/quote]



    Hi Anthony,



    Thanks for your idea.



    I've gone with it although I think it is less than ideal as 2 menus are generated for each page (adding to page weight and potential screen reader/text browser confusion), and hiding things with CSS feels 'hacky'.



    Would it be lots of work to have a condition which can match against navigation level?



    Steve

    [quote]
    I've gone with it although I think it is less than ideal as 2 menus are generated for each page (adding to page weight and potential screen reader/text browser confusion), and hiding things with CSS feels 'hacky'.

    [/quote]



    It's definitely not ideal, but the menu you are generating is also a little left of center. I think for a development solution a new show if condition would solve the problem, but that gets into the realm of coding time and cost.


    [quote]

    Would it be lots of work to have a condition which can match against navigation level?

    [/quote]



    I think that would depend on how the solution would be tackled. The only issue here I can see that we can't achieve with current functionality is to hide the first menu when a certain depth is reached (for which I can't think of another example we've implemented like that). We could do the second menu appearing using the method I described, or even using print tags inside a lineage for a non-css reliant solution.

    [quote]
    I think for a development solution a new show if condition would solve the problem, but that gets into the realm of coding time and cost.

    [/quote]



    How about a global asset keyword %globals_asset_lineagelevel% which could be used against a show_if regexp condition. I could imagine other uses for this kind of thing.


    [quote]

    using print tags inside a lineage

    [/quote]



    I hadn't pushed the idea this far in my head, but it is a good idea. It would at least prevent one menu being output when on the higher levels, if I get time to revisit our implementation I will add this.

    I'm looking at a similar problem, I think. I want to show a right-hand navigation on pages that are 2- or 3-levels deep where those pages have children.


    I'm currently using a Paint Layout to add an Asset Listing to the right hand side of the page. I don't want to use a menu_normal area because the menu has to appear within the content area layout.



    This successfully adds a menu, but I need to be able to toggle it off for pages that are at the top or first level deep - I think this is where the %globals_asset_lineagelevel% show_if would be great. (without switching it off, the right navigation just mirrors the left navigation submenu because they're both listing "children of the current asset")



    Is there any liklihood of this making it into Matrix?