Autonav - Child-pages shown with hidden parent-page

Permalink 4 users found helpful
Hi there !

I have a structure like this :

Home
- en
- - Page#1
- - Page#2
- - - Subpage#1
- - - Subpage#2
- - Page#3
- - hiddenpages
- - - hPage#1
- - - hPage#2


The "hiddenpages" is set to 'Exclude from nav'

In autonav i have :
Show pages : second level
Sub-pages to show : All
Level of subpages : All levels
Standard template


The problem is now, that while the sub-pages beneath Page#2 are show correctly, beneath Page#3 i have hPage#1 and hPage#2 shown, even they are not child-pages of Page#3 but child-pages of hiddenpages, an invisible parent-page.

How can i avoid that those child-pages are shown ?

I can't block them all, because i want to use them later as well for other autonavs (show pages beneath a certain page).

Thanks for input on this issue !

Marc-André

marcandre
 
sektorm replied on at Permalink Reply
I am having this same issue. I am using css to create dropdown menus...

If I have
Parent 1
Parent 2
- Kid 2
- Kid 2b
Parent (hidden)
- Kid 3
- Kid 3b

Kid 3 and 3b are showing underneath Parent 2 (following Kid 2b).

When I choose "relevent" (no kids show at all on ANY Parent and my drop down menu does not work. i must use all/all to make my drop down work) Any ideas?

Also, please note... relevent does not show any children at all.

Settings:
Top Level
Order Ascending
Display Sub Pages ?????? (relevent doesn't work)
Display Sub Page Levels - All

Thanks!!!
renic replied on at Permalink Reply
renic
Here is a simple patch to fix children of hidden parent being shown by the auto-nav block; however, It will not effect pages where the grandparent is set to hidden.
edit your "/block/autonav/view.php" (or the custom template you are using). And do the replacement listed below. It's not the most elegant solution, but it's functional.

If you do not have any files in "/block/" simply copy /concrete/block/autonav/view.php to /block/autonav/view.php

lines to replace (starts at line 9 or 10):
foreach($aBlocks as $ni) {
      $_c = $ni->getCollectionObject();
      if (!$_c->getCollectionAttributeValue('exclude_nav')) {


replace with:
foreach($aBlocks as $ni) {
      $_c = $ni->getCollectionObject();
      $ppObj = Page::GetById($_c->getCollectionParentID());
      if (!$_c->getCollectionAttributeValue('exclude_nav') &&
         (!$ppObj->getCollectionAttributeValue('exclude_nav') ||
         $_c->getCollectionID() == 1)
      ) {


Solution courtesy #concrete5 on freenode - JesperDK, Renic, MIRV-, and |ucas.
iconicschema replied on at Permalink Reply
I have been having this same problem and have been meaning to address it for a while now.

This solution will hide all descendants of a page that has the "Exclude From Nav" attribute set to true.

$excludedCIDs = array(); // array to reference excluded CIDs
   foreach($aBlocks as $ni) {
      $_c = $ni->getCollectionObject();
      if ($_c->getCollectionAttributeValue('exclude_nav')) { 
         $childrenArray = $_c->getCollectionChildrenArray(); // Get an array of children cIDs
         $excludedCIDs = array_merge($childrenArray, $excludedCIDs); 
         $excludedCIDs[] = $_c->getCollectionID(); // Add current cID to excluded array
         continue; // Move to next page
      }
      if (!in_array($_c->getCollectionID(), $excludedCIDs)  ) {
TheRealSean replied on at Permalink Reply
TheRealSean
went with this option, thanks for the tips.
Thanks to all the other devs for the other solutions to nice to see alternative methods.

Next time Ill just load Jordans template instead and start from there.

Thread Marked as Helpful :)
TheRealSean replied on at Permalink Reply
TheRealSean
I slightly amended this to also allow me to only show sub pages that I wanted to show,

I created an exclude_children page attribute,

then under the previous code just tweaked it slightly,
if ($_c->getCollectionAttributeValue('exclude_children')) {
$childrenArray = $_c->getCollectionChildrenArray(); // Get an array of children cIDs
$excludedCIDs = array_merge($childrenArray, $excludedCIDs);
}

This way I can show children of only certain blocks and hide those I do not want to appear, ie blog pages.

Im using both this and code above so that have slightly more granularity.

:doh: I just realised too that this is exactly what Jordanlev's Package does, sometimes I wish that I did research before jumping into the code.
imran replied on at Permalink Reply
Hi renic,

Thanks for your great tips i also this problem, but now i solved by your code with some changing because i have multi language site so thats why, i use:

$_c = $ni->getCollectionObject();
      $ppObj = Page::GetById($_c->getCollectionParentID());
      if (!$_c->getCollectionAttributeValue('exclude_nav') &&
         (($ni->getLevel() == 0) || !$ppObj->getCollectionAttributeValue('exclude_nav'))
      ) {
bennett49r replied on at Permalink Reply
bennett49r
Thanks Renic. This worked perfectly. Thanks for the detailed instructions!
jordanlev replied on at Permalink Best Answer Reply
jordanlev
FYI, I have a free addon that addresses this problem (it's a custom template, so it doesn't overwrite the default template -- hence you can still use that when needed in other parts of your site):
http://www.concrete5.org/marketplace/addons/autonav-exclude-subpage...
lucid replied on at Permalink Reply
lucid
Let me firstly say that I think that concrete5 is excellent. Only a couple days in and a great CMS for clients and developers.

I do however find this how autonav including subpages quite infuriating and not really in the sprit of the cms.

I've got the menu embedded in the template like this:
<div class="menu_nav">
         <?php
         $nav = BlockType::getByHandle('autonav');
         $nav->controller->orderBy = 'display_asc';
         $nav->controller->displayPages = 'top';
         $nav->controller->displaySubPages = 'all';
         $nav->controller->displaySubPageLevels = 'custom';
         $nav->controller->displaySubPageLevelsNum = 1;
         $nav->render('view');
         ?>  
      </div>


but it displays the subpages even though the parents have "exclude from nav" checked.

I couldn't used the plugin "Autonav Exclude Subpages " because my nav is embedded the the template so what I did was use the view from the plugin and added it to the autonav template folder.

<div class="menu_nav">
         <?php
         $nav = BlockType::getByHandle('autonav');
         $nav->controller->orderBy = 'display_asc';
         $nav->controller->displayPages = 'top';
         $nav->controller->displaySubPages = 'all';
         $nav->controller->displaySubPageLevels = 'custom';
         $nav->controller->displaySubPageLevelsNum = 1;
         //$nav->render('view');
         $nav->render('templates/exclude_subpages');
         ?>  
      </div>


hope this helps someone else in the future.
jordanlev replied on at Permalink Reply
jordanlev
Thanks for posting this solution -- I actually do this all the time but didn't bother mentioning it for some reason.

Do note that you can create a new directory on your server here:
YOURSITE/blocks/autonav/templates/

and drop the file in there (your template code would stay the same, C5 knows to look there). This is considered better than dropping it into here:
YOURSITE/concrete/blocks/autonav/templates/

...because if you update the system you'll lose the one inside the concrete directory.

-Jordan
lucid replied on at Permalink Reply
lucid
thanks Jordan. Done.
Good to know to use the blocks folder custom files.
dcaryll replied on at Permalink Reply
dcaryll
I'm currently having this issue where my blog sub-pages are showing in the menu under another page (not their parent page). If I exclude them from the nav, it won't show them in the Date Nav on the Blog page.

I am using a drop-down menu custom template on my blog already, so I can't add on Jordan's custom template.

Any ideas or suggestions to make the blog sub-pages not appear in the main navigation but still in the Date Nav. Or why my blog sub-pages are appearing under another non-parent page in the navigation? (The blog isn't even part of the main navigation)

Thanks for your help as always!
dcaryll replied on at Permalink Reply
dcaryll
Got it. I was still able to add Jordan's view.php in the blocks folder while using the Superfish custom template.

Auto-nav block is working much better now! :)
mehreenbaakza replied on at Permalink Reply
mehreenbaakza
Hi Jordanlev,

In my dropdown autonav, I have an Events page and want to hide it's child pages, as I don't want a dropdown full of 20 items. I want to keep the parent page visible though.

1. I tried creating the custom page attribute (check box) with the handle "exclude_subpages_from_nav" and then checked the box under the parent page properties. That didn't work.

2. I looked into your "Autonav Exclude Subpages" add-on but it's not compatible with version 5.6 (It's supposed to come with the package but I can't seem to find it anywhere)

Any clue how I can achieve this?
jordanlev replied on at Permalink Reply
jordanlev
This addon's functionality was included in the core system as of 5.6, so that's why it's not available for that version.

If you've upgraded a site from an earlier version of C5, though, and have the Autonav Exclude Subpages addon installed, it should still work just fine. If you created the "exclude_subpages_from_nav" attribute and applied it to the top-level page whose children you want excluded, that should do the trick. If not, try clearing your site cache via the C5 dashboard. Also check that the autonav block you're wanting to exclude subpages from actually has that custom template set to it. Also also check your SITEROOT/blocks/autonav/templates directory to see if maybe you overrode something with a different template that doesn't include this functionality?

Hope something in there helps :)
mehreenbaakza replied on at Permalink Reply
mehreenbaakza
First of all, thank you for your reply. I have version 5.6 installed out of the box, and so there are no older versions of your addon in the system.

I created the check box attribute exclude_subpages_from_nav the same way I created others such as replace_link_with_first_in_nav and it does appear under the page properties but checking the box has no impact, and the supages for that parent item still appear.

If this functionality is somehow buit into the core of 5.6, then how do we use it? I couldn't find it anywhere. I'm not using any custom templates and I've cleared the Site cache tons of times.

I really appreciate your help.
jordanlev replied on at Permalink Reply
jordanlev
Double-check that the handle for the attribute you created is this:
exclude_subpages_from_nav

(make sure the spelling is correct).

If you're using 5.6 it should just work -- I honestly have no idea why it wouldn't be (if the attribute handle is spelled correctly and you've checked the box for that attribute on a page).

You're checking the box on the parent page, right (the one that has the 30 pages under it -- not one of the 30 pages themselves)?
mehreenbaakza replied on at Permalink Reply
mehreenbaakza
I'm pretty sure I spelled it correctly but I will double check tomorrow. Ya, I tried to apply it to the parents page :-) thanks for all the help.
mehreenbaakza replied on at Permalink Reply
mehreenbaakza
OK, so I checked the spelling of the attribute I created and it's correct. When you mentioned that I may have overwritten something in the core autonav which is not picking up the exclude_subpages_from_nav attribute, I realized I could be using an older version of view.php in my autonav template (blocks/autonav/templates/dropdown_menu/)

I'm copying my view.php below - Would you mind looking at it and telling me if this is infact outdated? Where can I get an updated file for view.php? Thanks SO much!!!!!

<script type="text/javascript">
$(document).ready(function () {   
   $('.nav li').hover(
      function () {
         //show its submenu
         $('ul', this).slideDown(115);
      }, 
      function () {
         //hide its submenu
         $('ul', this).slideUp(115);         
      }
   );
});
</script>
   <?php
jordanlev replied on at Permalink Reply
jordanlev
I think you've discovered the problem. That template looks like the one from before 5.6.

You say this site is a fresh install of 5.6.0.2? If so, the new template is in concrete/blocks/autonav/view.php

If its an updated site though, it will be in updates/concrete5.6.0.2/blocks/autonav/view.php

Best of luck!
mehreenbaakza replied on at Permalink Reply
mehreenbaakza
I did resolve my problem, and thanks again for your help. You made me realize that I was overwriting some of the core features of the 5.6 autonav because I brought in a dropdown menu template from a previous project I did...and, although the CSS was still useful, the view.php should have been updated to the new version. I'm now using your clean blocks template for my dropdown's view.php :p Thanks!!!!!!!