We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4749
    • 623 Posts
    Back again! Did you guys miss me? Sorry, I pretty much live here now. So, anyway, I don’t have a problem per se, but I’m hoping for a solution. Here’s what I’d like to do.

    I’ve got a container full of documents. Each document is specific to one product. On the product page there’s a section for "recent news" about the product. I want to pull a couple links to those articles and post them in the "recent news" section. Well, here’s the deal, there is a huge repository of articles and blog entries to pull from, but how do I associate those with that product? I’d like ditto to grab the most recent articles that are in some way associated with the product. There will be overlap too. Some articles may talk about multiple products - which is fine. I just want to be able to pull those articles into the product page. What I’m having a tough time deciding is the logic. I realize I can create a new TV for each product and use all the &tag--- parameters, but can’t I automate it somehow to dynamically generate that list of tags or keywords with which to associate with the product?

    For example, I was thinking something along these lines:
     [!Ditto? &parents=`8,9,10` &tpl=`TPL` &tagData=`something here` &tagDelimiter=`,` &tagMode=`onlyTags` &tags=`something else here` &display=`2` &orderBy=`pub_date DESC`  !]


    &parents - these are the containers where the blog, news, and other articles can be found
    &tagData - where do I want to pull the data from
    &tags - how do I want to tag it?

    I’m just looking for a way to get it done. Thanks for looking.
      The MODx has you...
      Utah Web Design
      • 10226
      • 412 Posts
      You can create a tags array TV of some sort, and then manually go add the tags sad But from there you can just use a crazy parse / sort for ditto. I think this is more of a job for reflect, and I can’t tell you much more because I have never used it. I recall something called a tag cloud, not what you are looking for, but the base of that is what you need.

      Looks like you have a bit of work to do, but after that, when creating new articles, tags may be selected and calm water will be sailed.
        • 4749
        • 623 Posts
        Well, that’s just it. For these product pages I’ve already got a couple lists of tags, so when they’re created they will already have the associations I need in order to create the lists. Going back to the question, I think Ditto is what I need, but not sure exactly how to do it. Right now, I’ve got the call from my original post in place and I’m getting ’No documents found’ not sure what the deal is. I think I have it set up correctly. I’ll add the debug menu real quick and see what I can find.

        EDIT:
        Debug isn’t giving me anything good. There’s no real errors, but I wonder if my logic is just completely wrong. Am I clear in what I’m trying to do?
          The MODx has you...
          Utah Web Design
          • 4749
          • 623 Posts
          Thinking out loud here, could I use PHx to create some advanced "sequence without a variable" for my Ditto call? Kinda like in the Wiki:
          [+phx:if=`[+this+]`:is=`[+that+]`:then=`do this`:else=`do that`+]


          So I can trick Ditto in to retrieving the docs I want. Unless of course my logic is all messed up. It may be. I’m trying to pull articles and blog posts that have a connection with a specific product to display on the page as a "Related Articles" kind of idea. Just not getting there yet. Hmm. Is this not going to work?
            The MODx has you...
            Utah Web Design
            • 29774
            • 386 Posts
            Hi there,

            what you need to do is create a new multi-select list (or checkbox) TV for your article template, and dynamically populate that with your list of products. In the TV setup specify the Widget to be a delimited list with a comma as the delimiter. The input option values would be a Ditto call, something like this:
            @EVAL return substr($modx->runSnippet('Ditto', array("parents"=>"4","depth"=>"1","display"=>"all","showInMenuOnly"=>"0","sortBy"=>"pagetitle","sortDir"=>"ASC", "tpl"=>"@CODE ||[+pagetitle+]==[+id+]")), 2);
            


            Now you can create a relationship between an article and one or more products. On the product page you can then use Ditto with the tags parameter to output the most recent articles that are tagged with the current page id.
              Snippets: GoogleMap | FileDetails | Related Plugin: SSL
              • 4749
              • 623 Posts
              Thanks therebechips,
              That’s actually a brilliant solution and thanks for the idea, it really is good. However, in this case it won’t work...Well, it could, but there are over 700 products to associate with these articles, blog posts, and news postings. It would be overwhelming to select multiple products from a list of 700. Is there a way to make those associations with the existing setup? It might almost be easier for me to add the "tagged blogging" feature to the articles and new postings than to create a new tv with all the products. Couldn’t I then just use ditto to search for those tags? It obviously not working at the moment, but it would seem that it could be done that way. Any other thoughts on a possible solution? For some reason I can’t seem to wrap my head around the logic. For me it’s simple: There are keywords associated with all the documents I want to pull from. When I put together a Ditto call on the product page I should be able to say, "Ditto, look in these containers for documents with these keywords and return three results." Is this not realistic? Someone please tell me if I’m smokin’ something.
                The MODx has you...
                Utah Web Design
                • 29774
                • 386 Posts
                Blimey that’s a lot of products! Tagging is the way to go most certainly. You could use this snippet I wrote to output docs linked to a tag. All it does is reframe a Ditto call, but with the advantage that you can use it to generate a dynamic select menu/checkboxes TV based on a tag.

                <?php
                /*
                 * @name TagList
                 * @author Mark Croxton <[email protected]>
                 * @license Public Domain
                 * @version 1.0
                
                 * Outputs a formatted list of items for a given tag
                 * By default will generate a select menu for a TV
                */
                
                # grab data using Ditto
                $parents = isset($parents)? $parents : 0;
                $tag = isset($tag)? "$tag" : "";
                $tagData = isset($tagData)? $tagData : '';
                $rowTpl = isset($tpl)?  $modx->getChunk($tpl) : '||[+pagetitle+]==[+id+]';
                
                $output = '';
                $modx->runSnippet('Ditto', 
                	array(			
                	"parents"		=>$parents,
                	"depth"			=>"1",
                	"display" 		=>"all",
                	"sortBy"		=>"pagetitle",
                	"sortDir"		=>"ASC",
                	"save"			=>"2",
                	"tpl"			=>"@CODE [+id+][+pagetitle+][+introtext+][+".$tag."+]"
                	)
                );
                $aItems  = $modx->getPlaceholder("ditto_resource");
                
                # loop through and assemble a list for the tag
                if (is_array($aItems) && count($aItems)>0) {
                	for ($i=0; $i<count($aItems); $i++) {
                		if ($aItems[$i][$tag] == $tagData) {		
                			$fields = array('[+id+]','[+pagetitle+]','[+introtext+]');
                			$values = array($aItems[$i]["id"],$aItems[$i]["pagetitle"],$aItems[$i]["introtext"]);
                			$output .= str_replace($fields,$values,$rowTpl);
                		}
                	}
                }
                if (!isset($tpl)) {
                	$output = 'None==0'.$output;
                }
                return $output;
                
                ?>
                


                Alternatively you can use a straight Ditto tagging call, see
                http://wiki.modxcms.com/index.php/Category_Tagging_with_Ditto
                  Snippets: GoogleMap | FileDetails | Related Plugin: SSL
                  • 4749
                  • 623 Posts
                  Thanks! I just might be able to use this. I’ll work on it and see what I can figure out. I’ll post back my results.

                  [EDIT] Well, it wasn’t what I wanted to do initially, but I just converted my other two containers to use the "tagged blogging" features and I’m calling it all that way. So, it’s working the way I wanted it to, but not they way I was hoping to do it. Thanks for all the help.
                    The MODx has you...
                    Utah Web Design