We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16085
    • 203 Posts
    I have a template called News which references a chunk with the following ditto call:

    [!Ditto? &tpl=`main-news-TPL` &startId=`9` &display=`1`!]


    that then dumps into main-news-TPL (template);
    	<div class="content-News">  
    		<h1>[+#pagetitle+]</h1>  
    		<div class="content-NewsInfo"><b>Posted:</b> [*createdon:date=`%a %d, %b, %Y - %H:%M`*]</div>
    <div class="content-NewsInfo"><b>Article by:</b> [+author+]</div>
    			<div class="ditto_introText">[+#content+]</div>
    	</div>


    Now this works for the newest document but any past documents assigned this News template it doesn’t display the correct info, instead it displays the newest article within the old article. !?!

    I’ve tried using main-news-TPL within the main body of the News template but I’m stumped on how to replicate the nice phx using MODx’s standard tag, ie [+author+] and so on..

    It’s driving me ditto crazy as I can’t figure out the correct ditto call which I’m 100% sure is the problem.


    Please help..... huh not sure if I got this round the wrong way or what.
      • 7231
      • 4,205 Posts
      &startId is no longger in use, use &parents instead.

      http://ditto.modxcms.com/files/snippet-ditto-php.html#parents
        [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

        Something is happening here, but you don&#39;t know what it is.
        Do you, Mr. Jones? - [bob dylan]
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        Besides, Ditto was startID, Wayfinder is startId... that one bit me many times.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 16085
          • 203 Posts
          sooo confused.. I’ve change my Ditto call to use &parents but the past articles are still displaying the newest articles content
            • 10449
            • 956 Posts
            wait... if you want more than one article displayed, why do you use &display=`1` ?
            Also, you have no sortBy or sortDir parameters, so if you only pick one single article without these params, it will always pick the newest by default.

            http://ditto.modxcms.com/files/snippet-ditto-php.html
              • 16085
              • 203 Posts
              @ganeshXL, I only want it to display 1 article at a time.

              The news articles display fine, except for the weirdness of display newest article in the body of past articles. Which is bizarre as the document alias, menutitle displayed correctly just not the right document content...

              What I’ve done instead is put main-news-TPL into the body of the template News. I’ve install PHx plugin and it’s working as expected. My only problem is now pulling the correct author infomation like the [+author+] placeholder I was using from Ditto.

              	<div class="content-News">  
              		<h1>[*#pagetitle*]</h1>  
              		<div class="content-NewsInfo"><b>Posted:</b> [*createdon:date=`%a %d, %b, %Y - %H:%M`*]</div>
              <div class="content-NewsInfo"><b>Article by:</b> [+author+]</div>
              <div class="content-NewsInfo"><b>Article by:</b> [+phx:userinfo=`-username`+]</div>
              			<div class="ditto_introText">[*#content*]</div>
              	</div>



                • 7231
                • 4,205 Posts
                [+phx:userinfo=`-username`+]

                I think this should be:
                [+phx:userinfo=`username`+]


                  [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                  Something is happening here, but you don&#39;t know what it is.
                  Do you, Mr. Jones? - [bob dylan]
                  • 7231
                  • 4,205 Posts
                  OK, I see what is going on. In your Ditto chunk you are using document variables [* *] rather than placeholders [+ +] for the content, pagetitle and created date. Those should all be placeholders [+ +].

                  By using document variables the will always retrieve the current docs info rather than the doc being retrieved by Ditto.

                  See if this resolves the issue and report back the results. grin
                    [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                    Something is happening here, but you don&#39;t know what it is.
                    Do you, Mr. Jones? - [bob dylan]
                    • 16085
                    • 203 Posts
                    @dev_cw, still using Ditto Call:

                    [!Ditto? &tpl=`main-news-TPL` &parents=`9` &display=`1`!]


                    to main-news-TPL:

                    	<div class="content-News">  
                    		<h1>[+#pagetitle+]</h1>  
                    		<div class="content-NewsInfo"><b>Posted:</b> [+createdon:date=`%a %d, %b, %Y - %H:%M`+]</div>
                    <div class="content-NewsInfo"><b>Article by:</b> [+author+]</div>
                    			<div class="ditto_introText">[+#content+]</div>
                    	
                    	</div>


                    it’s still got an incorrect content issue. It’s like the newest document has dominance over any of the previous documents.

                    Okay, how do I tell the ditto call to only display the content of the document the link goes to. Don’t do anything other then simply display the content of that link.
                      • 16085
                      • 203 Posts
                      @dev_cw, sorry to keep switching. Using the same technic as above I’ve got the updated main-news-TPL in the body of template News.

                      Basically the article was printing out the user admin, and not the one I set it to via the Doc Manager => Set Authors, demo. Weird thing is if I go back to my previous Ditto call the [+author+] displays is the correct one.

                      So I was looking at what was in the PHx snippet and noticed;
                      // Returns the specified field from the user record
                      // positive userid = manager, negative integer = webuser

                      thus thinking [+phx:userinfo=`-username`+] was how you used it, just sure how you specifiy the correct negative number.

                      Now I still can’t figure out why the author isn’t printing what I expect is there any way of ripping Ditto’s author output to use in PHx.

                      // set author placeholder
                      		if (in_array("author",$this->fields["display"]["custom"])) {
                      			$placeholders['author'] = $this->getAuthor($resource['createdby']);		
                      		}
                      
                      	// ---------------------------------------------------
                      	// Function: getAuthor
                      	// Get the author name, or if not available the username
                      	// ---------------------------------------------------
                      	
                      	function getAuthor($createdby) {
                      		global $modx;
                      		
                      		$user = false;
                      		if ($createdby > 0) {
                      			$user = $modx->getUserInfo($createdby);
                      		} else {
                      			$user = $modx->getWebUserInfo(abs($createdby));
                      		}
                      		if ($user === false) {
                      			// get admin user name
                      			$user = $modx->getUserInfo(1);
                      		}
                      		return ($user['fullname'] != "") ? $user['fullname'] : $user['username'];
                      	}