Trying to create a hide from navigation function


#1

I have browsed the forums and looked at the solutions for this already but I can’t seem to get it working.

I have a type of checkbox on the blueprint and I can’t seem to check if it’s true. I think I am missing something.

So far I have tried:
<?php if($item->visiblemenu() == '1' && $item->hasVisibleChildren()): ?>
<?php if($item->visiblemenu() == '1' || $item->hasVisibleChildren()): ?>
<?php if($item->bool() && $item->hasVisibleChildren()): ?>
<?php if($item->bool() || $item->hasVisibleChildren()): ?>

I am trying to hide the team members subpage content that is used in the about page from the demo site from the navigation I am generating.


#2

Have you tried

<?php if($item->visiblemenu()->bool() && $item->hasVisibleChildren()): ?>

But the first option should also work.


#3

The solution still doesn’t work because the menu now doesn’t show any sub-pages and if I use || it shows everything. Am I able to do something like ->bool('1')?


#4

What do you want to check and what do you want to happen in each case? Maybe post the complete code as well, not only that single line?

The && operator means, both conditions must be true. The || operator means, one of the conditions must be true.

And no, bool('1') does not exist and does not make sense.

<?php if($item->visiblemenu()->bool()) {
  echo "This line will be echoed if the checkbox `visiblemenu` was checked.";
}
?>
<?php if($item->visiblemenu()->bool() && $item->hasVisibleChildren()) {
  echo "This line will be echoed if the checkbox `visiblemenu` was checked **AND** the page has visible children. If one of the conditions is false, nothing will be echoed";
}
?>

#5

Hmmm, OK. So I am trying to check if it has visible sub-pages, and if the visiblemenu checkbox is ticked then I want it to hide itself from the menu.

I have simply modified the example menu that was provided with the multi-language demo site provided.

<nav class="menu-panel" id="jMenuContainer" role="navigation">
	<div class="menu-panel__wrapper" id="jMenuPanel">
		<ul class="menu-panel__container">
			<li class="menu-panel__title">
				<h4>Info &amp; Services</h4>
			</li>
			<?php foreach($pages->visible() as $item): ?>
				<li class="<?= r($item->isOpen(), 'is-active') ?>">
					<a href="<?= $item->url() ?>" role="button"><?= $item->title()->html() ?></a>
					<?php if($item->hasVisibleChildren() && $item->visiblemenu()->bool()): ?>
						<ul>
							<li class="menu-panel__title">
								<h4><?= $item->title()->html() ?></h4>
							</li>
							<?php foreach($item->children()->visible() as $subitem): ?>
								<li class="<?= r($subitem->isOpen(), 'is-active') ?>">
									<a href="<?= $subitem->url() ?>" role="button"><?= $subitem->title()->html() ?></a>
								</li>
							<?php endforeach ?>
						</ul>
					<?php endif ?>
				</li>
			<?php endforeach ?>
		</ul>
	</div>
</nav>
<!-- END: menu-panel -->

So I guess I might need 2 if statements or try to check if not ticked with something like if(!$item->visiblemenu()->bool())?

I have little PHP knowledge so this is the first time trying to work with it in any dev sense. I am a HTML, CSS & jQuery Monkey by profession haha.


#6

Maybe something like this?

<?php if($item->hasVisibleChildren() && !$item->visiblemenu()->bool()): ?>

But this still doesn’t work.


#7

What does “it does not work” mean in this case? What is the result? And what is wrong with the result?


#8

The result is still outputting all subpages.

Could it be something to do with the blueprints? It is the standard about & team blueprint provided with the demo site with the addition of this new checkbox field type on the team blueprint.


#9

Well, that’s the problem. You are checking the field on the main pages, so the checkbox should be in the about template.


#10

Hmmm, I want the option of hiding things from specific pages but not all of them. I want to use embedded content stuff like about/team provided in the demo site but hide them from the menu BUT I also want sub-pages of about that are visible.

So how would I achieve something like:

  • Home
  • Projects
    • Project A
    • Project B
  • About
    • Bob Meowsky (Hidden)
    • Cat Winslot (Hidden)
    • Awards (Visible)
    • Sponsors (Visible)
  • Contact
  • Etc…

#11

Ah, ok, now we are talking. That’ a completely different story, then you have to check on the subpage, not the parent:

<nav class="menu-panel" id="jMenuContainer" role="navigation">
  <div class="menu-panel__wrapper" id="jMenuPanel">
    <ul class="menu-panel__container">
      <li class="menu-panel__title">
        <h4>Info &amp; Services</h4>
      </li>
      <?php foreach($pages->visible() as $item): ?>
        <li class="<?= r($item->isOpen(), 'is-active') ?>">
          <a href="<?= $item->url() ?>" role="button"><?= $item->title()->html() ?></a>
          <?php if($item->hasVisibleChildren()): ?>
            <ul>
              <li class="menu-panel__title">
                <h4><?= $item->title()->html() ?></h4>
              </li>
              <?php foreach($item->children()->visible() as $subitem): ?>
                <?php if($subitem->visiblemenu()->bool()): ?>
                  <li class="<?= r($subitem->isOpen(), 'is-active') ?>">
                    <a href="<?= $subitem->url() ?>" role="button"><?= $subitem->title()->html() ?></a>
                  </li>
                <?php endif ?>
              <?php endforeach ?>
            </ul>
          <?php endif ?>
        </li>
      <?php endforeach ?>
    </ul>
  </div>
</nav>
<!-- END: menu-panel -->

#12

OK cool, we are getting closer :slight_smile: haha

You missed out a closing ) btw :stuck_out_tongue:

This section should only output if there are actually sub-pages

<li class="menu-panel__title">
    <h4><?= $item->title()->html() ?></h4>
</li>

So I’m guessing I will need 2 if statements or move the if statement outside somehow.

Because at the moment About still thinks it has a sub-page and when i click through it is just the title - so I need to move this into the visiblemenu check somehow (I’m guessing)

(BTW I really do appreciate your help :slight_smile:)

EDIT - It can’t move inside the foreach as it’s the parent page’s title


#13

You do know that I just leave them parenthesis out all the time to test your coding skills, don’t ya :stuck_out_tongue_winking_eye: ?

Well, if I look at your structure above, the About page does have subpages that you want to show, doesn’t it? But of course, we could check if a pages has subpages and if there are any subpages that should be shown like this by extending the check for visible children a bit:

<?php if($item->hasVisibleChildren() && $item->children()->filterBy('visiblemenu', '1')->count()): ?>

#14

After you first helped me, I looked out for it when it broke :wink: haha

OK cool, this works - I just need to add in the visiblemenu to every blueprint now. Is there a way I can do that globally? Like is there a way to set default fields for all blueprints?


#15

No, that’s no possible. But you can define global field definitions, so less stuff to type.


#16

Thank you very much. I will continue building my sitemap and functionality requirements and I’m sure I will be back soon with another question haha.