Jump to content

Hide/mask a parent page from front end


Peter Knight
 Share

Recommended Posts

Short explanation

Is it possible to hide a page from front-end output but keep the ability display it's children?

Ideally I'm looking for a solution that doesn't involve htaccess or nginx

So lets say I have a breadcrumb trail of:

Home > News > Posts > news story 1

and I want to mask off the folder called Posts so it becomes just

Home > News > news story 1

I still want to retrieve the child pages of Posts using selectors etc.

Long explanation

I'll give you a use case...

I start off with a News section and its children are news stories. 

News (name=news, template=news-container)

- news post 1 ( template=news-item)

- news post 2 ( template=news-item)

- news post 3 ( template=news-item)

- news post 4 ( template=news-item)

The structure above lets me use the Add New function because the Parent and Children both have very specific templates and settings.

Client then tells me that there are News child pages which are not news items.

Lets say they want to add pages called Public Relations Contacts, Media Enquiries and Events

They need to be child pages of News but they can't go in the root. They don't need a news-item template and I don't want them to be pulled into any selectors targeting template=news-item or parent=/news/ etc

What I usually end up doing is putting all the news items inside a hidden folder called Posts and redefining the Family settings to retain the Add New functionality

News (name=news, template=news)

 - PR Contacts

 - Media Enquiries

 - Events

 - Posts (name=posts, template=news-container)

 - - news post 1 ( template=news-item)

 - - news post 2 ( template=news-item)

 - - news post 3 ( template=news-item)

 - - news post 4 ( template=news-item)

The problem is that my breadcrumb trail looks like this

Home > News > Posts > news story 1

Although it's logical and structurally sound, there's a duplicate there in terms of content. Both News and Posts pages display a list of News items.

I'm probably not describing this very well but maybe you have the same issue and have a solution?

Link to comment
Share on other sites

For the url you would have to use urlSegements and do a check if a children has the name. Example:

<?php
// in your news template you add the following 
$childPage = $pages->get('/'.$input->urlSegement1.'/');

if(!($childPage instance of NullPage) {
echo $childPage->render();
exit;
}


?>
Link to comment
Share on other sites

If you don't care about the urls showing the name of the wrapping page, than it's not that difficult. 

$page->parents("template!=news-container");

And in the news-container.php:

$session->redirect($page->parent->url);

Hey. I should have mentioned, it's really any/everywhere that I want to mask the parent page name. Particularly URLs and breadcrumb trails.

Otherwise, thanks for the tips. I'll test during the week.

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

×
×
  • Create New...