+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 18

Thread: a for each for pages?

  1. #1
    Join Date
    Dec 2008
    Posts
    87

    Default a for each for pages?

    perhaps there is a way to do this. but i am still picking up deki wiki and all, so i do not know.

    the setup: category page called "servers" and underneath it we have each server. each server has a section for things like IP address, admin passwrd, and such.

    What i'd like to be able to do is dynamically grab this content and throw it all on one page.

    So basically, need to grab all the children pages of the "servers" section, and then for each of those, display the sections of things like name, IP address, and role.

    this way, we can summarize on the server page, or do other things like that.

    I can grab children pages, and I can grab a particular section for a page, i was just hoping i could do it recursivly through pages and for multiple sections.

    Any tips?

  2. #2
    Join Date
    Jul 2006
    Location
    San Diego, CA
    Posts
    5,450

    Default

    You can do it, but it requires a bit of work depending on how you've layed out the data. For example, if your pages are sub-pages of a known page, you can just ask for the subpages (easy). However, if your pages are all over the place, you'll need to use search (harder). Similarly, if you have use some kind of semantic structure to annotate the data inside page, it's very easy to get to it using an xpath. Otherwise, you'll need to rely on the structure of the page or proximity of keywords, which is harder.
    Steve G. Bjorg - Chief Architect
    Did you check the MindTouch FAQ?
    Found a bug? Report it.
    Follow me on Twitter
    Find us on IRC: irc.freenode.net #mindtouch

  3. #3
    Join Date
    Mar 2008
    Posts
    1,630

    Default

    Do you have a particular layout you're already committed to using, or are you still in the stage of deciding how to lay out the info?

    If the former, show what it is and we'll see what's the best way to extract the desired data. If the latter, then describe your requirements and we can offer suggestions on how to make it workable.

    As Steve says, this is 100% doable but the details could vary widely.

  4. #4
    Join Date
    Dec 2008
    Posts
    87

    Default

    ok,

    A: awesome!
    B: i thought I was clear. what good are you guys if you can't read my mind? jeeze...

    well, i'm open to data structures. all up for "best practices".

    how I have it now:

    Servers
    -server1
    -server2
    -server3

    as the tree. then each server has multiple h5's. for example.. IP address, OS running, service tag... and so forth.

    (and BTW. totally open to using h1's, then h2's, then h3's if thats a better way! i personally don't know whats best. do let me know the wiesest way.. still setting up templates so change isn't a problem...)

    and yes, all the pages are nicely ordered. do not need to grab pages from all over the place.

    "servers" has 3 children pages. iit's from these pages i want to extract data, so i can list all IP addresses... or list all names and IP addresses.. mashup data like that.

    does that make sense?

  5. #5
    Join Date
    Feb 2008
    Posts
    286

    Default

    I have done something like that. You need to do 3 basic steps.

    1. Have a uniform structure
    2. Write code to itterate through each page
    3. Write code to extract the data from each page.

    To extract the data, you have to identify it in the layout
    Code:
          <tr> 
            <td style="text-align: right;"><strong>Date</strong></td> 
            <td id="ArticleDate"> </td> 
          </tr>
    Then use an xpath statement to extract that information

    entry['//*[@id=\'ArticleDate\']']

    I don't have long to give you a full example right now, but hopefully this is a step in the right direction for you.

  6. #6
    Join Date
    Dec 2008
    Posts
    87

    Default

    Sorry, i still don't know how to extract the data. Still picking up deki script... so not at all aware of how and what's yet.

    each pae has sections (h5) that can be used as identifiers...

  7. #7
    Join Date
    Mar 2008
    Posts
    1,630

    Default

    Actually, if each datum is in its own section, you can just use wiki.text() to fetch the contents:
    Code:
    {{
    foreach (var p in wiki.getpage("path_to/servers").subpages) {
      var ipaddress = wiki.text(p.path, "IP Address");
      var servername = wiki.text(p.path, "Name");
      ...etc...
    
      ...display as desired...
    }
    }}
    That shows the basic structure. Of course, the details are dependent on exactly what you want to do.
    Last edited by neilw; 12-15-2008 at 12:28 AM.

  8. #8
    Join Date
    Dec 2008
    Posts
    87

    Default

    wow! a foreach! I didn't know that was an option... cool!

    so, lets say, running with what you have, that I want to display a table with the server name and it's IP address. 1 column for the name and one for the IP address, of each page below /Servers. (for that matter, is it possible to grab a page title like that? )

    Would "display as desired" allow for throwing in html to create a table, like that?

  9. #9
    Join Date
    Mar 2008
    Posts
    1,630

    Default

    Sure. I'd strongly suggest you look at some of the official Dekiscript documentation; this will all be a lot easier if you've first absorbed some of the fundamentals.

    The standard way to fill a table with information like this would be by using HTML statements. You need to edit the source to do this.

    Here's a very simple example; you should be able to hack it to work in your situation:
    Code:
    <table class="table">
     <tr>
      <th>Server name</th>
      <th>IP Address</th>
     <tr>
     <tr foreach="var p in wiki.getpage('path_to/servers').subpages">
      <td>{{ wiki.text(p.path, "Name") }}</td>
      <td>{{ wiki.text(p.path, "IP Address") }}</td>
     </tr>
    </table>
    Set the argument in wiki.getpage() to the path of your servers page. Set the section names in the wiki.text() calls to wherever you have server name and IP address stored.

    When you go back to the WYSIWYG editor, you'll see the table with the header row and a single data row; the hidden "foreach" attribute will loop and generate a table row for each server when the wiki page is displayed. In the WYSISYG editor, you can tweak the appearance of the table and the contents of the individual cells. You only need the source editor to modify the Dekiscript inside the attributes.

    If you have the page variable for a wiki page (such as the loop variable "p" above), then p.title will give you the page title. See the documentation for the wiki variables, especially the all-important page variable.

  10. #10
    Join Date
    Dec 2008
    Posts
    87

    Default

    I actually did try finding some tutorials and all for deki wiki... what I found wasn't that great. I didn't know about that though... will certainly check it out, since I'm planning on using deki wiki a lot...

    Yes, I did figure I'd have to edit from source and all.. and it worked! which is awesome...Actually it's really awesome, because it works exactly how I would expect it to.

    And this is why deki wiki is so awesome...

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts