Autonav in 3rd party template
Permalink
Hi,
We are building a website for a local photographer. The website itself is powered by Concrete5 however we decided to use PhotoCart for the Gallery/Store section.
We would like any changes to the site navigation to appear in the PhotoCart template as well. I have a solution that almost works, I'm hoping someone can help me with the last piece.
1) Enable events in site.php:
2) Hook into the relevant events in site_events.php:
3) Code store.php to load a custom autonav template
4) Code the custom template to output to a file instead of echoing
4) Include menu.html in my PhotoCart template.
5) ???
6) Profit
Any help with step 5 would be appreciated. Everything works, except menu.html is 1 change behind. I add a page but it doesn't show up. I add another page and then the first is there but not the second.
Thanks in advance.
Jeff Paetkau
We are building a website for a local photographer. The website itself is powered by Concrete5 however we decided to use PhotoCart for the Gallery/Store section.
We would like any changes to the site navigation to appear in the PhotoCart template as well. I have a solution that almost works, I'm hoping someone can help me with the last piece.
1) Enable events in site.php:
define('ENABLE_APPLICATION_EVENTS', true);
2) Hook into the relevant events in site_events.php:
Events::extend('on_page_add', 'Store', 'regenerateMenu', 'models/store.php'); Events::extend('on_page_duplicate', 'Store', 'regenerateMenu', 'models/store.php'); Events::extend('on_page_delete', 'Store', 'regenerateMenu', 'models/store.php'); Events::extend('on_page_move', 'Store', 'regenerateMenu', 'models/store.php'); Events::extend('on_page_update', 'Store', 'regenerateMenu', 'models/store.php');
3) Code store.php to load a custom autonav template
class Store { function regenerateMenu($objPage) { $bt_main = BlockType::getByHandle('autonav'); $bt_main->controller->displayPages = 'top'; $bt_main->controller->orderBy = 'display_asc'; $bt_main->controller->displaySubPages = 'none'; $bt_main->render('templates/echo'); } }
4) Code the custom template to output to a file instead of echoing
$echo ='<ul class="nav">'; //opens the top-level menu foreach ($navItems as $ni) { $echo .='<li class="' . $ni->classes . '">'; //opens a nav item $echo .='<a href="' . $ni->url . '" target="' . $ni->target . '" class="' . $ni->classes . '">' . $ni->name . '</a>'; if ($ni->hasSubmenu) { $echo .='<ul>'; //opens a dropdown sub-menu } else { $echo .='</li>'; //closes a nav item $echo .=str_repeat('</ul></li>', $ni->subDepth); //closes dropdown sub-menu(s) and their top-level nav item(s) } } $echo .='</ul>'; //closes the top-level menu file_put_contents("./menu.html", $echo);
4) Include menu.html in my PhotoCart template.
5) ???
6) Profit
Any help with step 5 would be appreciated. Everything works, except menu.html is 1 change behind. I add a page but it doesn't show up. I add another page and then the first is there but not the second.
Thanks in advance.
Jeff Paetkau