Jump to content

Show different layout if no children or siblings?


Roych
 Share

Recommended Posts

Hello,

I need some help with somethin Im working on.

I want to show different design if the current page doesn't have siblings or children.

I'm using basic-page template for all my articles (siblings, children and normal pages all with the same fields) and Im showing sidebar with siblings or children on all of them. But when the page doesn't have any of them I want it to be without the sidebar.

I tried with:

<?php namespace ProcessWire;?>
<?php $nosidebar = $page->hasChildren() ;?>
CODE WITH SIDEBAR
<?php elseif ($page->siblings()) :?>
CODE WITH SIDEBAR
<?php elseif (!$nosidebar) :?>
CODE WITHOUT SIDEBAR
<?php endif ;?>

It kinda works as it should but it shows shows me the sidebar on a page without children or siblings.

Tried everything and got kind a lost here. Not even sure if this is the right way to do this.

Any help greatly appreciated. Thank you

R

Link to comment
Share on other sites

<?php
namespace ProcessWire;
$showsidebar = 0;

// Set $showsidebar to 1 if the page has children or siblings
if($page->hasChildren() || count($page->siblings(false)))
  $showsidebar = 1;
  
if($showsidebar) {
// Code with Sidebar
} else {
// Code without Sidebar
}

I think this should work, untested ? 

  • Like 1
Link to comment
Share on other sites

thank you for anwser

I's not working as it should. I'll try to be more clear what I need.

My tree menu looks like this: (messy I know)

Articles (all below have "basic-page" template)
- Page (should have sidebar with siblings)
- Page  (should have sidebar with siblings and children)
-- Page (should have sidebar with siblings)
-- Page (should have sidebar with siblings and children)
--- Page (should have sidebar with siblings)
--- Page (should have sidebar with siblings and children)
---- Page (should be full width)
Page (should be full width)
Page ( should be full width)
Page ( should have sidebar with siblings or children)
- Page (should be full width)

So if there is page a page on it's own it should also be without sidebar. 

I hope you understand what I need.

Thank you very much

R

Link to comment
Share on other sites

9 hours ago, Roych said:

thank you for anwser

I's not working as it should. I'll try to be more clear what I need.

Just replace 

if($page->hasChildren() || count($page->siblings(false)))

with

if($page->hasChildren())

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...