We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31037
    • 358 Posts
    EDIT: Solved: See end of post.

    ------------
    I’m sure I’m just missing something obvious, but I’ve been sitting for several hours trying to figuring this out:

    I want to display the name of the parent folder (the folder the post belongs to) in a listing of recent published documents. But there is no document object for "parentpagetitle" which I can put in as a placeholder.

    Tried to create my own placeholder in a snippet (my first snippet smiley ) by using $modx->getParent and setPlaceHolder which worked fine, but that was stupid! It just looks up the parent page title of the page I’m calling from, and not the parent title for the rows (listed documents).

    Ok, don’t tell me how stupid I am, just give me a hint how to do this wink I just started building my first real site with MODx, and it’s easy to miss something obvious. And right now I’m really tiered, have been studying PHP for many hours today, before my petty attempts with MODx! It’s late here! smiley

    Thanks! smiley

    EDIT: Solved:

    My (first one ever) snippet worked:

    $title = $modx->getParent($id,1,’pagetitle’);
    return ($title[pagetitle]);

    Called my snippet with [[snippetname? &id=`[*id*]`]]

    Just didn’t know that calling a snippet is like calling a function. When I put in "return" in my minimal snippet it worked! Wow, now I understand how easy MODx is to work with! Been working with an old Mambo site for the last week, everything there is very hard to customize!

    Next thing is to figure out how to make a placeholder that is accessible for my chunks, but thats another story and not for this thread.

    I realize there is ready made snippets for retrieving other documents info with better functionality, but this works for me!
    :)
      • 7923
      • 4,213 Posts
      Glad that you got it solved already and also learned new things on the way. Thats the best outcome. Just to let you know that there is a snippet called getfield to get some field from spesific document and from [*parent*] you can get the parent doc id.


        "He can have a lollipop any time he wants to. That's what it means to be a programmer."
        • 16429
        • 254 Posts
        	$modx->setPlaceholder($ph,$value);
        


        Where $ph is the name of the placeholder and $value is the string which replaces the placeholder.

        Example:

        $ph = 'namePh';
        $phValue = 'kudo';
        $modx->setPlaceholder($ph,$phValue);
        $output = 'Hello by [+namePh+]';
        return $output;
        


        The placeholder will be [+namePh+] and the output will be "Hello by kudo".

        Ok? wink
          kudo
          www.kudolink.com - webdesign (surprised?)

          [img]http://www.kudolink.com/kudolinkcom.png[/img] [sup]proudly uses[/sup] [img]http://www.kudolink.com/modx.png[/img]
          • 31037
          • 358 Posts
          Thank you for your replies! (No need waisting time reading rest of this post, nothing important here wink)

          @Doze: Isn’t that called cheating? Using someone else’s snippet? Just kidding tongue
          It was when I was looking into the getDoc snippet I realized how I should do it! But I’ll use getField next time smiley

          @Kudolink: Thank you for your example, but why would I need to have "Hello by kudo" on my site? Just kidding again tongue

          I do understand how to create a placeholder, but I’m not sure what would be the best way using it when I want to use the created placeholder in a call from a Ditto row template used to list several docs. Calling the snippet directly in the call does work great, but it looks a bit ugly:

          <a href="[~[+id+]~]">
          <span class="date">[+date+]</span>
          <span class="category">[[getParentPageTitle? &id=`[+id+]`]]</span>
          <span class="title">[+title+]</span>
          </a>

          It would look nicer using a placeholder like <span class="category">[+phGetParentTitle+]</span>

          Should I call the snippet for creating the placeholder in the template, or is there a way to make the created placeholder accessible "globally" so I can use the placeholder without calling the "createPhSnippet" for each row?

          Actually, there is no reason answering this, just me tinking out loud. Thinking out loud is sometimes the best way learning something! And I’m just curious how to do this in a nice looking "MODx-way" smiley

          (Though not needed, I know someone will answer this, because this is a MODx forum. Opposite to the Mambo forums there is always someone answering the posts, even this kind of unnecessary "thinking-out-loud-what-I-could-figure-out-my-self" post. laugh)
            • 11975
            • 2,542 Posts
            Hi,

            you could replace the snippet call by the name of a chunk containing it.

                           <a href="[~[+id+]~]">
                           <span class="date">[+date+]</span>
                           <span class="category">{{getParent}}</span>
                           <span class="title">[+title+]</span>
                           </a>


            where getParent chunk is

            [[getParentPageTitle? &id=`[+id+]`]]


            :-)
              Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
              • 16429
              • 254 Posts
              Quote from: Uncle68 at Oct 26, 2006, 05:10 AM

              @Kudolink: Thank you for your example, but why would I need to have "Hello by kudo" on my site? Just kidding again tongue
              Because I’d like to greet you everytime you look at your site grin
              Quote from: Uncle68 at Oct 26, 2006, 05:10 AM

              Should I call the snippet for creating the placeholder in the template, or is there a way to make the created placeholder accessible "globally" so I can use the placeholder without calling the "createPhSnippet" for each row?
              After looking at the setPlaceholder() function I think it replaces the placeholder while parsing the document as a whole. I’m a noob at php, I think if you are more comfortable with php than me you can look at the function (it’s in manager/includes/document.parser.class.inc.php) and understand what I mean.
              Quote from: Uncle68 at Oct 26, 2006, 05:10 AM

              (Though not needed, I know someone will answer this, because this is a MODx forum. Opposite to the Mambo forums there is always someone answering the posts, even this kind of unnecessary "thinking-out-loud-what-I-could-figure-out-my-self" post. laugh)
              This is, in fact, the more productive community I’ve never partecipated in.
              It’s so good to be here grin
                kudo
                www.kudolink.com - webdesign (surprised?)

                [img]http://www.kudolink.com/kudolinkcom.png[/img] [sup]proudly uses[/sup] [img]http://www.kudolink.com/modx.png[/img]