5.7 pages under external links

Permalink
I am using C5 5.7 and I am trying to create collapsible sub menus in an autonav however this requires in the sitemap to have an external link linking to '#' with pages under it.
This is so I can apply JS to the top # link to toggle the view of its subpages.

Is this possible and if so how can I achieve this?

 
MrKDilkington replied on at Permalink Best Answer Reply
MrKDilkington
Hi wbargent,

I don't believe you can add subpages to an external link.

An alternative to this might be to make a custom template for the Auto-Nav block.

Here is an example using the Responsive Header Navigation custom template:
concrete\blocks\autonav\templates\responsive_header_navigation\view.php
https://github.com/concrete5/concrete5/blob/develop/web/concrete/blo...
// Original
// echo '<a href="' . $ni->url . '" target="' . $ni->target . '" class="' . $ni->classes . '">' . $name . '</a>';
//
// if the navitem is level 1 and has subpages, then the href value will be "#", else use the URL for the href value
echo '<a href="' . ($ni->level == 1 && $ni->hasSubmenu ? '#' : $ni->url) . '" target="' . $ni->target . '" class="' . $ni->classes . '">' . $name . '</a>';

This makes the top most level pages, that have subpages, link to "#".

Can you offer more details about what you are trying to make.
wbargent replied on at Permalink Reply
Thanks, this seems to work however the sub pages are also set to have a href of # which is a problem. I only want the top page to have a href of # if it has sub pages.

I hope that makes sense.
MrKDilkington replied on at Permalink Reply 2 Attachments
MrKDilkington
@wbargent

I am attaching an example custom template and screenshot of the HTML it outputs.

- unzip top_level_hash.zip into application\blocks\autonav\templates (create the folders if they do not already exist)
- after unzipping, you should have this path available
application\blocks\autonav\templates\top_level_hash\view.php
- apply the Top Level Hash custom template to the Auto-Nav block
Click on the Auto-Nav block and choose Design & Custom Template from the popup menu. A new menu bar will appear, choose the gear icon "Custom CSS Classes, Block Name, Custom Templates and Reset Styles" on the right side. From the Custom Template drop down menu, select Top Level Hash.
wbargent replied on at Permalink Reply
I still have the same problem.
MrKDilkington replied on at Permalink Reply 1 Attachment
MrKDilkington
@wbargent

What settings are you using for the Auto-Nav?

I am attaching a screenshot of the settings I am using for my example.
wbargent replied on at Permalink Reply
The same, only difference is I am selecting the page I want the nav to display.
MrKDilkington replied on at Permalink Reply
MrKDilkington
@wbargent

You need to change the level to match the page you selected. The top most level is 1.
$ni->level == 1
wbargent replied on at Permalink Reply 1 Attachment
This is what my autonav outputs. The 4 items under the IT services menu are my submenu items. I want them to have a link however I want the IT services button to have a link of # and the buttons above to also have their original links.

When the Level is set to 1 the submenu and its parent gets a # link; when its set to 2 only the submenu get a link set to #.
MrKDilkington replied on at Permalink Reply
MrKDilkington
@wbargent

This will check if the page name is "IT Services". If true, the href value will be "#". If false, it will be the regular URL.
echo '<a href="' . ($ni->name == 'IT Services' ? '#' : $ni->url) . '" target="' . $ni->target . '" class="' . $ni->classes . '">' . $ni->name . '</a>';
wbargent replied on at Permalink Reply
In the future I will have more drop down's and I would rather not modify the code each time.