Jump to content

Mapping 2 Page Trees


Soma
 Share

Recommended Posts

Is there any easy way to map two indentical tree branches. So a reference can be set from one to the other page in the same hierachical place in the other branch.

What would be the most straight approach looping them both.

I thought simplest would be a simple find to get a flat page array of both then simply loop them both and map page to page. Or not?

Is there a way to use key's in page array?

Example of the branches to map:

/de/

 -page1

   -page1.1

 -page2

/en/

 -page1

   -page1.1

 -page2

Link to comment
Share on other sites

Is there any easy way to map two indentical tree branches. So a reference can be set from one to the other page in the same hierachical place in the other branch.

If the pages used the same URL names (minus the root), then it would be relatively easy to map them. But for multi language pages, I'm guessing you'd want language specific URL names. So I think that would leave you with having to map them by page reference.

I thought simplest would be a simple find to get a flat page array of both then simply loop them both and map page to page. Or not?

While you could loop both like that, I think it might be challenging. The sort order would not be predictable unless you forced some order.  But your two branches would have to match up exactly in order to map them.

It seems like a page reference back to the master tree, for each page, would be the simplest way to map them. That way you would not have to ensure each tree is identical.

Is there a way to use key's in page array?

PageArrays are keyed by integers, and those integers only represent when the page was added to it. Meaning, they aren't useful for mapping. However, you can treat PageArrays like regular arrays and manually force them to use page IDs, but I'm not sure that would be useful in your case.

Can you tell more about what you are trying to do? Maybe there are other approaches that would become clear with a broader look.

Link to comment
Share on other sites

Thanks Ryan.

Yes I'm trying but the sort order makes it impossible. Though there subdirs that are sorted by name so they would work, but the ressort pages arent and they don't appear same position in page array with a find.

No I can't use names... since they're language specific.

I tried following:

<?php
$de = wire("pages")->get("/de-ch/halbjahresbericht-2011-2012")->find("include=all");
$en = wire("pages")->get("/en-ch/halfyearreport-2011-2012")->find("include=all");

foreach($de as $key => $p){
$e = $en[$key]->name;
echo "<p>page: $p->name";
echo "<br/>page: $e</p>";

}

yes I got a page reference field to reference them, but first nee to find a simple solution to not do it manually page by page. And yes the structur is 1:1. It's not for runtime on the site, but after import of these pages.

---

Attached image so you see the two trees.

post-1337-132614279951_thumb.png

Link to comment
Share on other sites

Without some common field to tie them together, all you've got is structure and order. I don't think it's safe to grab the whole structure in one field operation because there won't be a consistent way to map the sorting. I think you have to go through it one page at a time, keep track of what level you are at, and use children() recursively. Perhaps not far off from a simple site-map script:

http://processwire.com/sitemap.sh.txt

But even in this case, the two trees would have to be identical in hierarchy, quantity of pages, and order, to map them properly. Maybe that's okay, but still something to consider.

Link to comment
Share on other sites

Thanks for your time Ryan. Yes I agree it isn't an easy thing.

I'm now doing it level for level. First ressorts, then subpages. There aren't that much for now.

BUT, in the future they will have more reports with ~150 page per language and It would be great if there's would be a simpler solution for doing this. :) The pages I import from an html files structure into PW, so I'll may consider having this done before import using a name/key field something.

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...