We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30100
    • 58 Posts
    *Solution* If you need a variable passed on as a parameter in a cached snippet call, use a wrapper snippet (see post #9).



    I’ve been using a method to use TV based chunks for my site from the guide on http://wiki.modxcms.com/index.php/Create_TV-Based_Chunks

    This is a great solution that I like verry much, but I’m now having a problem with a ditto call when I try to use [*parent*] for ditto’s &parents=`` parameter. The ditto call is inside an uncached chunkListParser snippet call. Can I use some binding like @EVAL to get the parent id in the cached ditto call.

    [!chunkListParser? &chunks=`[*funktioner_sidinnehall_mitten*]` &wrapperdiv=`funktioner_sidinnehall_mitten`!]


    [[Ditto? &sortBy=`createdon` &sortDir=`ASC` &language=`svenska-utf8` &parents=`[*parent*]` &display=`all` &summarize=`5` &paginate=`1` &paginateAlwaysShowLinks=`1` &tpl=`mall_produkter_lista`]]
    <p>Visar <strong>[+start+]</strong> - <strong>[+stop+]</strong> av <strong>[+total+]</strong> Produkter | Sida <strong>[+currentPage+]</strong> av <strong>[+totalPages+]</strong> </p> <p>[+previous+] [+pages+] [+next+]</p>


    Or are there some other ways to make it possible to call the snippets inside "chunkListParser" uncached? That would be even better
      • 4749
      • 623 Posts
      I may be completely wrong, but you may be looking for [[UltimateParent]] instead of [*parent*]. I don’t even think [*parent*] is a tv, unless you made something custom. Try [+id+] or [[UltimateParent]]
        The MODx has you...
        Utah Web Design
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        Yes, [*parent*] is the parent ID of the current document. But I can’t figure out why the ditto call would want to use its own parent as the starting point? The document with the Ditto call will be displaying the list of summaries from all of the documents that are children of that document specified. How can it have a summary of itself?
          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
          • 4749
          • 623 Posts
          I learn something new everyday! smiley
            The MODx has you...
            Utah Web Design
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            And [+parent+] would be the parent ID of the document being processed for a summary. Be careful of the distinction between the two! [* ... *] is like any other tv or document variable, it applies to the document itself (the one with the Ditto call on it). [+...+] applies to the document being processed by Ditto. So if you accidentally use [*id*] for the link creation in your Ditto template, all the URLs will be the same... to the document containing the Ditto call!
              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
              • 30100
              • 58 Posts
              I have a product page that consists of the product page to the right and a ditto call that lists other products that has the same parent "folder", so I need the ditto call to make a list of the products in the current parent folder. The problem is that all my snippet calls are nested "inside" the snippet-call chunkListParser (to make the site based on components that you could click on and off) so all my html generating snippets has to be called cached like [[snippet]] and then variables like [*parent*] in [[Ditto? &parents=`[*parent*]`]] won’t work since you have to call it uncached [!Ditto? &parents=`[*parent*]`!] for a variable call to work.

              I don’t know if I’m explaining in an understandable way here... undecided

              I wonder if it’s possible to get MODx to treat the variable [*parent*] in the cached ditto call ( [[Ditto? &parents=`[*parent*]`]] ) as it would if it was uncached, maybe with a @BINDING like @EVAL or something, something that gets priority to run before the ditto call so that ditto sees the call like [[Ditto? &parents=`35`]] so that the right category shows in my product site. See the picture below.
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                Is there a reason why you cannot specify the parent ID in that Ditto call? Also, only if you have nested snippets (the inner snippet’s output being the value of the outer snippet’s parameter) you need the uncached/cached nesting form. TVs should work whether the snippet is cached or not.

                Perhaps it will work if you filter out the current document (use [*id*] as the filter criteria)?

                If you could post the actual snippet calls you’re using (including the chunkListParser snippet) I’ll set this up on my local dev server and see what I can make of it. I’d like to see the actual structure of the page this is all on as well.

                  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
                  • 30100
                  • 58 Posts
                  *This post got really long, the actual problem are at the end of the post but here you can read how it all works.*

                  There is a few different chunk’s, snippet’s and one TV that is included so this can get quite a large post, it’s allso in swedish I’m afraid, here is the order and code:

                  1. A document that has a number of TV’s like product image, price and so on and some TV’s that decides which chunks to be included in the document (a way to only have one template per css design, I want the site to easily change appearance). I used the guide I found on http://wiki.modxcms.com/index.php/Create_TV-Based_Chunks.

                  2. A TV that decides if the document content is a text site or a product, the value are set to "produktinnehall".
                  Variabelnamn (variable name):	[*funktioner_sidinnehall_mitten*]  
                  Inmatningstyp (input type):	Radio Options
                  Inmatningsvärden (input value):	@EVAL return $modx->runSnippet('getChunks',array('category'=>'funktioner_sidinnehall_mitten'));
                  Standardvärde (standard value):	textinnehall
                  Widget:	Delimited List
                  Delimiter: ,
                  


                  3. The getChunks snippet code are:
                  <?php
                  $q_chunks = $modx->db->query('
                  		SELECT
                  		chunk.*
                  		FROM '.$modx->getFullTableName('site_htmlsnippets').' AS chunk
                  		INNER JOIN '.$modx->getFullTableName('categories').' AS category
                  		ON chunk.category = category.id
                  		WHERE
                  		category.category IN ("'.$category.'")
                  		ORDER BY
                  		name
                  	');
                  
                  	$ar_chunks = array();
                  	while ($row = $modx->db->getRow($q_chunks)) {
                  		$ar_chunks[] = $row['name'];
                  	}
                  
                  	$l_chunks = implode("||",$ar_chunks);
                  	return $l_chunks;
                  ?>


                  4. The category "funktioner_sidinnehall_mitten" contains two chunks: produktinnehall (this is the value set) and textinnehall

                  5. A chunk that is inserted in the middle of the product document:
                  		{{funktioner_sidinnehall_overst_vanster}}
                  	<div id="sidinnehall">
                  		{{funktioner_sidinnehall_over_hoger}}
                  		{{funktioner_sidinnehall_mitten}} (this is the intresting chunk)
                  		<div id="funktioner_botten">
                  			{{funktioner_sidinnehall_under_vanster}}
                  			{{funktioner_sidinnehall_under_hoger}}
                  			<div class="rensa">
                  				{{funktioner_sidinnehall_botten_vanster}}
                  			</div>
                  		</div>
                  	</div>

                  Above this chunk is the html head and open body tag chunk and below the footer

                  6. The chunk "funktioner_sidinnehall_mitten" contains a snippet call to "chunkListParser" that basically includes the chunks that has the same names set by the TV "funktioner_sidinnehall_mitten" that in our case is set to "produktinnehall". In short, this call includes the chunk "produktinnehall" in the final document. All snippet calls from now on has to be called chached as I understand it since this call is uncached, if I try an uncached snippet from now on I only get the call printed in the final document (as usual).
                  [!chunkListParser? &chunks=`[*funktioner_sidinnehall_mitten*]` &wrapperdiv=`funktioner_sidinnehall_mitten`!]


                  7. The chunkListParser snippet code are:
                  <?php
                  $ar_chunks = split(',',$chunks);
                  	$ar_chunks = array_unique($ar_chunks);
                  
                  	$output = '';
                  
                  	foreach ($ar_chunks as $chunk) {
                  		if ($chunk != '') {
                  			$c = $modx->getChunk($chunk);
                  			if ($c) $output .= $c;
                  		}
                  	}
                  
                  	if ($output != '' && isset($wrapperdiv)) {
                  		$output = '<div id="'.$wrapperdiv.'">'.$output.'</div>';
                  	}
                  
                  	return $output;
                  ?>


                  8. The chunk "produktinnehall" contains:
                  			<div id="produktfalt">
                  				<h1 class="centrera">[*pagetitle*]</h1>
                  				<div class="centrera"><img src="[*produkt_bild*]" alt="[*pagetitle*] width="250px" /></div>
                  				<div class="produkt_pris"><p>[*produkt_pris*]:-</p></div>
                  				<div id="produkt_text">[*content*]</div>
                  			</div>
                  			<div id="sidfalt_ram">
                  				<div id="sidfalt">
                  					<p>[[Breadcrumbs? &showHomeCrumb=`0` &showCurrentCrumb=`0`]]</p>
                  					{{produkter_lista}}
                  				</div>
                  			</div>
                  			<div id="sidfalt_ram_hoger"></div>
                  			<div class="rensa"></div>

                  This is basically two parts, one (first part where id=produktfalt) that shows the current product on the right side and one (id=sidfalt) that has the chunk call {{produkter_lista}} that lists the other products in the same folder/category (has the same parent).

                  9. The chunk "produkter_lista" contains:
                  [[Ditto? &sortBy=`createdon` &sortDir=`ASC` &language=`svenska-utf8` &parents=`35` &display=`all` &summarize=`5` &paginate=`1` &paginateAlwaysShowLinks=`1` &tpl=`mall_produkter_lista`]]
                  <p>Visar <strong>[+start+]</strong> - <strong>[+stop+]</strong> av <strong>[+total+]</strong> Produkter | Sida <strong>[+currentPage+]</strong> av <strong>[+totalPages+]</strong> </p> <p>[+previous+] [+pages+] [+next+]</p>

                  This is where my problem is, when I set the &parents=`` parameter to 35 as in the code, everthing is fine as long as I only want to have one product catergory, computer parts a document container with document id 35 but when I change &parents=`35` to &parents=`[*parent*]` the product list in the final document lists the documents in the root instead of the products in the current documents parent folder.

                  That’s all the code, to me it seem like the variable [*parent*] is set to 0, if I make the ditto call with parents parameter empty like &parents=`` I get the output "No documents found" instead of the root documents for the site so maybe I have thought the wrong way of this problem, maybe the ditto call gets the [*parent*] value from the wrong document, why else would it be set to `0` and not ``.

                  I still have to find how to get it set to 35 when viewing a document inside the computer parts folder and det to 10 when viewing a document inside the shoe folder...

                  I’ve attatched a screen dump of the document structure, it’s simple but might help visualizing.

                  *edit*
                  I tryed with filter parameter instead like:
                  [[Ditto? &sortBy=`createdon` &sortDir=`ASC` &language=`svenska-utf8` &parents=`3` &display=`all` &summarize=`5` &paginate=`1` &paginateAlwaysShowLinks=`1` &tpl=`mall_produkter_lista` &filter=`parent,[*parent*],1` &depth=`10`]]


                  But the result is "No documents found", when I write [*parent*] outside the ditto call I get the output 35 and if I set &parents=`35` it works but &parents=`[*parent*]` does not.... How do I make it to prioritize [*parent*] so that is filled in before the ditto call is executed?
                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    ok, I see what you are trying to do. I’ll see what I can work out, and maybe someone else will see possibilities I’ll miss.
                      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
                      • 7231
                      • 4,205 Posts
                      Mybe you could use a wrapper snippet to get the Parent Id and feed it to Ditto.

                      Here is an example:
                      <?php
                      // identify the parent
                      $parent = $modx -> documentObject['parent'];
                      
                      // use the parent in the ditto call
                      $ditto_output = $modx->runSnippet("Ditto", array(
                      	"parents" => $parent,
                      	"display" => "all",
                      	"summarize" => "5",
                      	"language" => "svenska-utf8",
                      	"paginate" => "1",
                      	"paginateAlwaysShowLinks" => "1",
                      	"tpl" => "mall_produkter_lista" ));
                      
                      // output the ditto results
                      return $ditto_output;
                      
                      ?>

                      So if you name the snippet MySnippet you would change where you have the Ditto call to:
                      [[MySnippet]]
                      <p>Visar <strong>[+start+]</strong> - <strong>[+stop+]</strong> av <strong>[+total+]</strong> Produkter | Sida <strong>[+currentPage+]</strong> av <strong>[+totalPages+]</strong> </p> <p>[+previous+] [+pages+] [+next+]</p>

                      I have never used this sort of setup with the pagination links, so not sure if that could be an issue.

                      Note: the code above is untested and straight from memory shocked
                        [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]