Danjuan Posted September 14, 2015 Share Posted September 14, 2015 (edited) Hey guys i've just started with processwire so be gentle. I've managed to use ajax on the site to load dynamic content using the delayed output method but it seems to be duplicating my navigation menu. In my main.inc file I have the following: Navigation and Content. <!doctype html> <html lang="en"> <head> <script type="text/javascript"> $(document).ready(function() { $("#topnav a").click(function() { $("#topnav a.on").removeClass('on'); // unhighlight selected nav item... $(this).addClass('on'); // ...and highlight new nav item $(".content").html("<p>Loading...</p>"); $.get($(this).attr('href'), function(data) { $(".content").html(data); }); return false; }); }); </script> </head> <body> <ul id='topnav'><?php // Create the top navigation list by listing the children of the homepage. // If the section we are in is the current (identified by $page->rootParent) // then note it with <a class='on'> so we can style it differently in our CSS. // In this case we also want the homepage to be part of our top navigation, // so we prepend it to the pages we cycle through: $homepage = $pages->get("/"); $children = $homepage->children; $children->prepend($homepage); foreach($children as $child) { $class = $child === $page->rootParent ? " class='on'" : ''; echo "<li><a$class href='{$child->url}'>{$child->title}</a></li>"; } ?></ul> <div class='content'> <?= $content ?> </div> </body> </html> Here's my home.php (Other template files are the same for the time being): <?php $content = $page->body; ?> It replaces the content just fine but I don't want it duplicating the rest of the page? What am I doing wrong? Edited September 14, 2015 by Danjuan Link to comment Share on other sites More sharing options...
LostKobrakai Posted September 14, 2015 Share Posted September 14, 2015 if(!$config->ajax){ // render Nav } Link to comment Share on other sites More sharing options...
Danjuan Posted September 14, 2015 Author Share Posted September 14, 2015 Hi Thanks for the quick reply. I'm still getting to grips with processwire, where do I put that? Thanks Link to comment Share on other sites More sharing options...
LostKobrakai Posted September 14, 2015 Share Posted September 14, 2015 Wherever you echo out content, that shouldn't be part of any response to ajax calls. Link to comment Share on other sites More sharing options...
Danjuan Posted September 14, 2015 Author Share Posted September 14, 2015 Hi LostKobrakai Just figured it out but didn't replay quick enough. Thanks for your help and the very speedy response. Link to comment Share on other sites More sharing options...
bernhard Posted September 14, 2015 Share Posted September 14, 2015 hi danjuan, welcome to the forum - have fun with processwire you can also mark questions as solved: https://processwire.com/talk/topic/10838-wirerenderfile-not-returning-string-output/#entry101930 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now