Calling "new Area('Auto_nav');" twice in page types doubles the output.

Permalink
Hi everyone. I'm subcontracting a project for another developer in concrete5 5.6, updating a custom theme to a twitter bootstrap responsive site. I've had no end of troubles (he is unwilling to update to 5.7) but my most recent struggle is one that I have been unable to find an answer to.

In order to avoid breaking his already existing design for displays 992px and over, I simply added a second header section with menu included, then toggled between the two using bootstrap's hidden classes. However, I have found that calling the same menu area causes the resulting list ('li') items to be repeated—example 'Home Contact About Home Contact About'. This is all in the same unordered list ('ul')!

Does anyone know what's going on? Is there a way for me to avoid this? Any advise on how to get around this behavior?

I haven't worked with concrete5 before this, so if I am making an obvious rookie mistake I apologize for the trouble. Just couldn't find anything on this problem.

Thank you for whatever insight you can provide!

 
hutman replied on at Permalink Reply
hutman
One way that I think you can avoid this is to put this somewhere at the top of the file

$autoNav = new Area('Auto_nav');


Then where you want to output the nav, just put this line in each place

$autoNav->display($c);
thejadmaster replied on at Permalink Reply
I tried this and, unfortunately, got the same result. Every time the 'display($c)' is called, it seems to increase the list item output in the next one.

It was a good idea though, thank you. :)
hutman replied on at Permalink Best Answer Reply
hutman
That's really interesting. Here is a workaround that seems to work.

In the first nav spot put this

<?php
$autoNav = new Area('Auto Nav');
if($c->isEditMode()){
   $autoNav->display($c);
} else {
   ob_start();
   $autoNav->display($c);
   $navContent = ob_get_clean();
   echo $navContent;
}
?>


and in the second one put this

<?php 
if(!$c->isEditMode()){
   echo $navContent;
}
?>
thejadmaster replied on at Permalink Reply
Awesome! Got it to work with your workaround, though I don't quite understand what was done here.

Thanks so much for the assistance! :)
hutman replied on at Permalink Reply
hutman
Basically what it does is if the page is in Edit Mode it outputs the block in the standard way, in only one place.

If the page is not in edit mode it captures the output and assigns it to the $navContent then echos that in each place. There is something as you stated with the display function of an area containing an Auto Nav that causes the Auto Nav to duplicate itself in a really weird way.
thejadmaster replied on at Permalink Reply
Hmm... that makes sense. Clever work around, hutman, though it's too bad it seems to be necessary.

Thanks again for the help, and for following up with an explanation for your fix. I really appreciate it.