alexm Posted March 24, 2014 Share Posted March 24, 2014 Hi guys, New to the forums so I'm looking forward to having some great discussions. First off, I'd obviously like to say what a great CMS/F, very neat and tidy and super simple to use. Nice one Ryan. And secondly the community looks great. Hopefully someone can help me with this... I see other similar topics on the forums but none that clear up this point. I have a one page site. I have used child pages of home as the different sections of the one page site. This populates MarkupSimpleNavigation with the menu system for the one page site as more sections are generated. That's perfect. Now however lets say there is an about page. If I browse to domain.com/about/ I would like to hide the page and return 404. As this page is being pulled in by the home page. And shouldn't be accessible via url. Now the problem is I have templates assigned to each child page for obvious styling reasons so I can't create a page without a template file assigned. How can I show hidden pages on the home page? I have in my home.php template foreach ($page->children() as $c) { echo $c->render(); // render the pages } where I want to render each other page and template. if I try to add foreach ($page->children("include=hidden") as $c) { echo $c->render(); // render the pages } I get redirected to domain.com/page/ with the following message: "The page you were looking for was not found" "Please use our search engine or navigation above to find the page" Could anyone shed any light on how I might go about solving this? I don't mind having the pages hidden on the backend so this solution would be fine if it worked. Thanks, Alex Link to comment Share on other sites More sharing options...
Joss Posted March 24, 2014 Share Posted March 24, 2014 Just for interest, if the menu is simply sending visitors to anchor text further down the home page (I assume that is how it is working), why would anyone know to go to /about/ in the first place? If there is no link like that on the page, surely that URL wont be indexed by the search engines. Link to comment Share on other sites More sharing options...
renobird Posted March 24, 2014 Share Posted March 24, 2014 alexmercenary, How complex is the navigation? Do you even need a module? Set the child pages to hidden, and then try this: <ul> <? foreach ($page->children("include=hidden") as $c): ?> <li><a href="#<?=$c->name;?>"><?=$c->title;?></a></li> <? endforeach ?> </ul> P.S. Welcome to the forums. 1 Link to comment Share on other sites More sharing options...
alexm Posted March 24, 2014 Author Share Posted March 24, 2014 @joss it's more a case of tidiness etc. @renobird - thanks for the welcome. I don't think I made myself very clear. Sorry. The nav works fine. But Im using the separate pages on the backend as sections of a one page design. Now as these are pages I can still access them via their URL's. As Joss points out this probably won't matter if there are no links to the page but I'm just wondering out of interest if there is a way of showing the hidden pages within my loop which grabs the different pages as sections of the one page design? If not it's not a massive deal I guess, but more of a thought. Thanks guys, sorry about the delayed reply, didn't get a notification of replies. I'm now following the topic so I guess I should. Link to comment Share on other sites More sharing options...
renobird Posted March 24, 2014 Share Posted March 24, 2014 Right. Sorry, I didn't have coffee today. I see, you need to set them to unpublished if you really don't want them accessible via URL. Link to comment Share on other sites More sharing options...
alexm Posted March 24, 2014 Author Share Posted March 24, 2014 Yea it's odd, because when I do that I get the page not found message on the home page. Link to comment Share on other sites More sharing options...
renobird Posted March 24, 2014 Share Posted March 24, 2014 alexmercenary, Coffee kicking in now. I think you can pass an $options array to render (I know there is a post on this, but I can't find it). foreach ($page->children("include=hidden") as $c) { echo $c->render(array('isInclude' => true)); // render the pages } In the template file for your child pages: if(isset($options['isInclude']) && $options['isInclude'] == true) { // code for your section } else { $session->redirect("/"); } Link to comment Share on other sites More sharing options...
renobird Posted March 24, 2014 Share Posted March 24, 2014 I don't think you even need to have your child pages set to hidden, they can be published as normal. Link to comment Share on other sites More sharing options...
renobird Posted March 24, 2014 Share Posted March 24, 2014 Found it. https://processwire.com/talk/topic/3145-multiple-views-for-templates/?p=32876 Link to comment Share on other sites More sharing options...
alexm Posted March 24, 2014 Author Share Posted March 24, 2014 Hmm still as soon as I add include=hidden it just breaks the homepage and redirects to domain.com/page/ with the page not found message. Perhaps I should just use an after hook to redirect. I dunno. My heads not in it either right now. Coffee didn't help me, ha! Link to comment Share on other sites More sharing options...
alexm Posted March 24, 2014 Author Share Posted March 24, 2014 Your logic in post #7 seems like the right idea to me but it's just not happening. Oh well. Link to comment Share on other sites More sharing options...
renobird Posted March 24, 2014 Share Posted March 24, 2014 Can you post your code? Link to comment Share on other sites More sharing options...
alexm Posted March 24, 2014 Author Share Posted March 24, 2014 I have a home.php file with basically the head and the footer and elements which are static. Then where I'm pulling in the pages with their templates assigned I'm literally using that code already posted <?php foreach ($page->children() as $p) { echo $p->render(); // render the pages } ?> Then in each template there is just your usual eg. <section class="arrow" id="<?php echo pageIdAttr($page->url); ?>"> <div class="container inner"> <div class="thin"> <div class="section-title"> <h2><?php echo $page->title; ?></h2> </div> <div class="row"> </div> <!-- /.row --> </div> </div> </section> <?php echo renderTestimonial($pages->get(1002)->testimonial_repeater, 0, 'yellow', $config->urls->templates); ?> Thanks Link to comment Share on other sites More sharing options...
renobird Posted March 24, 2014 Share Posted March 24, 2014 And that code will output any child pages that are not set to hidden — correct? Link to comment Share on other sites More sharing options...
alexm Posted March 24, 2014 Author Share Posted March 24, 2014 Correct. As it stands if I change a child page of home to hidden it breaks the homepage that pulls in the children and redirects to domain.com/page/ with the page not found message. Link to comment Share on other sites More sharing options...
renobird Posted March 24, 2014 Share Posted March 24, 2014 That is weird. So if you just change the status to hidden it breaks? Even without adding hidden children to the $page->children pageArray? Seems like something else is happening to cause that. I can't recreate it here. Link to comment Share on other sites More sharing options...
alexm Posted March 24, 2014 Author Share Posted March 24, 2014 Sorry I'm telling a porky pie. If I set include=hidden that breaks it. Link to comment Share on other sites More sharing options...
renobird Posted March 25, 2014 Share Posted March 25, 2014 Hi alexmercenary, I can confirm that the following works, and will indeed create a single page website where the child pages are included in the homepage, and are not accessible via URL. You don't need to set the child pages to hidden, the template logic takes care of the 404. In my home.php template <?php include("./head.inc"); foreach ($pages->get('/')->children() as $p) { echo $p->render('children.php', array('isPartial' => true)); } include("./foot.inc"); In my children.php template (assigned to all children of the home page) <?php if (isset($options['isPartial']) && $options['isPartial'] == true): ?> <section class="arrow" id="<?=$page->name; ?>"> <h2><?=$page->title; ?></h2> </section> <? else: ?> <?php throw new Wire404Exception(); ?> <? endif; ?> 4 Link to comment Share on other sites More sharing options...
diogo Posted March 25, 2014 Share Posted March 25, 2014 Should work as Reno is doing, but even before we could pass parameters to render() this would be possible by comparing the url with the page being rendered. In your case: if ($page->url == $_SERVER["REQUEST_URI"]) throw new Wire404Exception(); 2 Link to comment Share on other sites More sharing options...
renobird Posted March 25, 2014 Share Posted March 25, 2014 diogo, Nice one. That method is cleaner for sure. I would go that route in this case. I've always set this up where there are multiple views, never needed to just prevent a direct view. Link to comment Share on other sites More sharing options...
alexm Posted March 25, 2014 Author Share Posted March 25, 2014 renobird, diogo... Thank you both so much for your help! diogos method works a charm as I'm sure would yours renobird, like you say it's just a bit cleaner for the purpose of what I want to achieve. You are both legends. What a lovely forum full of caring people!! Thanks again 2 Link to comment Share on other sites More sharing options...
renobird Posted March 25, 2014 Share Posted March 25, 2014 No worries. Glad to help. 1 Link to comment Share on other sites More sharing options...
Soma Posted March 25, 2014 Share Posted March 25, 2014 Sorry to dive in late. Diogo's code would be equalent to: if($page->url == $page->url) throw .... Just looks cooler, but however I would simply not create the php template for those pages and create a separate template file. If your template would be "subpage", create a partial-subpage.php And render the subpages on home with echo $subpage->render("partial-subpage.php"); And since you don't have a subpage.php those won't be viewable anyway. Redirect: What you also could do is have the subpage.php redirect to the home with a hash /#yoo appended, so you could scroll to the panel and also use that url for indexing. $session->redirect("/#" . $page->name); 6 Link to comment Share on other sites More sharing options...
alexm Posted March 25, 2014 Author Share Posted March 25, 2014 That's another killer idea. Ok i'll take a look at this for future reference! Link to comment Share on other sites More sharing options...
diogo Posted March 25, 2014 Share Posted March 25, 2014 Diogo's code would be equalent to: if($page->url == $page->url) throw .... Soma, something is wrong there... 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