PDA

View Full Version : Recursive Listing and Wildcards



saintsservers
10-30-2008, 01:05 PM
I have the following structure of Deki Pages:
Product 1/Forums/Forum1
Product 1/Forums/Forum2
Product 1/Forums/Forum3

Product 2/Forums/Forum1
Product 2/Forums/Forum2
Product 2/Forums/Forum3

I'm interested in what the DekiScript would look like to produce the following result:
Product 1:
- Forum 1
- Forum 2
- Forum 2
Product 2:
- Forum 1
- Forum 2
- Forum 3

I can't merely use wiki.tree with a depth of 2, as I have lots of other categories aside from Forums within each Product. In essence, I am looking for wildcards along the lines of: wiki.tree (*/Forums/). Any ideas?

Regards,

Lewis

craigsivils
10-30-2008, 01:40 PM
It can be done. You set up a foreach loop on the page.subpages and then for each subpage do a wiki.tree on the forums page underneath it.

saintsservers
10-30-2008, 06:54 PM
I apologize for my ignorance, I am still slightly new to DekiScript. How close am I with the below:


var products = wiki.getpage('/Products');

foreach(var product in products.subpages)
{
var productforums = product.page.title .. "/Forums";
wiki.tree(productforums);
}

saintsservers
10-30-2008, 07:15 PM
Nevermind - figured it out - Thank you!

crb
11-04-2008, 10:45 PM
Can you post the code, so anyone else reading the thread can see the fixed version?

saintsservers
11-05-2008, 02:36 AM
{{
var product_page = wiki.getpage('/Products');
var product_array = [];

foreach(var product in product_page.subpages)
{
let product_array ..= [ { title:product.title } ];
}

let product_array = list.sort(product_array, 'title');

foreach(var product in product_array)
{
product.title;
var product_forums = "Products/" .. product.title .. "/Forums";
if (wiki.getpage(product_forums))
{

}
else
{

}
}

}}


I hope this helps.

Lewis

SteveB
11-12-2008, 02:37 PM
You can probably simplify the code slightly, like this:


{{
var product_page = wiki.getpage('/Products');
var product_array = list.sort(map.values(product_page.subpages), 'title');

foreach(var product in product_array)
{
product.title;
var product_forums = "Products/" .. product.title .. "/Forums";
if (wiki.getpage(product_forums))
{

}
else
{

}
}

}}