Jump to content

Including a page in another page in a Multisite setup


Tyssen
 Share

Recommended Posts

This question follows on from the discussion that starts here.

A screenshot of the page tree is attached. On the subsite, the content of About displays OK, but all the subpages of About only display the page title.

Template code is:

<?php

/**
 * NPL Page template
 *
 */

if(count($page->includePage)>0) $page = $page->includePage;

$outMain = '<h1>'.$page->title.'</h1>';

$outMain .= $page->body;

include("./npl-main.inc.php");

post-967-0-29769300-1409311215_thumb.png

Link to comment
Share on other sites

This is not really possible. It will render the page as it would be on your main site like navigation links etc.

Also this is not possible like this:

$page = $page->includePage;

This will only replace the variable $page with the other page object, but only autoloaded fields like "title". But ID and other fields etc won't.

If then, this would be more like it:

wire()->fuel->set("page", $page->includePage);

But then $page will be the other page with all it's properties, which may or may not come in your way.

Link to comment
Share on other sites

What you're saying seems to conflict with what MadeMyDay is saying in the other thread. FWIW

if(count($page->includePage)>0) $page = $page->includePage;

works for npl.dev-server.dnsalias.com/about/ but not npl.dev-server.dnsalias.com/about/club-history/ etc.

Link to comment
Share on other sites

Ah right just setting $page to another page when rendering the content in a template would work I guess for that page yes, but that's all. It's not "the" other page in other places maybe like navigation etc, in other modules or PW system, it's just in your template at that time.

It depends a lot where you and how you do this. Of course for children of that page it won't work just so. I think mademyday already mentioned other approaches that maybe work, with url segments etc. 

Edit: I don't think it's all that easy and what pitfalls and drawbacks this all would have, and don't know what all the factors are that you need to render pages from another site. Usually what I think is the approach to just juggle with $page objects leads to unexpected results and should be avoided, more so if you don't know what you're (or PW) doing.

Link to comment
Share on other sites

What you're saying seems to conflict with what MadeMyDay is saying in the other thread. FWIW

if(count($page->includePage)>0) $page = $page->includePage;

works for npl.dev-server.dnsalias.com/about/ but not npl.dev-server.dnsalias.com/about/club-history/ etc.

A screenshot of the page tree is attached. On the subsite, the content of About displays OK, but all the subpages of About only display the page title.

 

The title and body should work also for childpages. Not sure what you mean. DO you have now each child page create under the subsite /about/? And you use a page field reference to select the mainsite under /about/? That would be ok to create dummy pages and do that, and your code should work. But can't really help to find the problem as I'm not in front of it.

Also mademyday made some valid points over here https://processwire.com/talk/topic/1025-multisite/?p=71136

Somehow it is be possible to display content from the main site and use url segments and output the fields on the subsite. If you don't understand how to get this going, may we can provide example code to get you a start. It's just hard to follow for me ATM. :)

Just create only the About page on the subsite. And use a template on which you enable url segments under its url configuration screen.

It has no children. The main site in root has About page with children.

Code to test for url segment and get page from main site. On the About page of subsite.

// if needed, don't allow more than 1 url segment and show 404

if(count($input->urlSegments) > 1) throw new Wire404Exception();

// when 1 url segment found like /about/childpagename/

if(count($input->urlSegments) == 1) {

   $childname = $sanitizer->pageName($input->urlSegment1);
   $original = $pages->get("/about/$childname/"); // try get the original page
   if(!$original->id) throw new Wire404Exception(); // not a page

   // if we got this far we're on a child page, so render content from it
   // but were still on the /subsite/about/

   echo "<h1>$original->title</h1>";
   echo $original->body;
   ...

} else {

  // we're on /about/ subsite, so maybe just show a list
  // of the original children from main site with url and a segment

  foreach($pages->get("/about/")->children as $child) {
    echo "<h3>$child->title</h3>";
    echo "<p>$child->summary</p>";
    echo "<a href='$page->url{$child->name}'>view more</a>"; // now construct url using child page name
    
    // if page name of main site is also /about/, you can even just use $child->url.
    // as that will already be the correct url we need here
    echo "<a href='$child->url'>view more</a>";
  }

}

Edit: Just an example, had rewritten some.

  • Like 1
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...