We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36562
    • 94 Posts
    Modx version being used: Rev 2.2.0pl

    From a snippet i am sending an array of data to chunk A

    Array holds:
    key=value


    Chunk A looks:
    [[+key]]


    Output of that chunk is: value

    Now i wanna pass that key to another chunk. But thats where my problem is , it doesnt work. Example:

    Chunk A now holds :
     [[$newchunk? &key=`[[+key]]` ]]


    newchunks holds:
    [[+key]]


    But this is an empty output. If tried calling newchunk with !$ (unchached) same result. But if i call it with
    &key=`something`
    then it works. Am i doing something wrong, or cant i pass a placeholder?
      --------------------------------------
      www.williamastrom.se
      • 36562
      • 94 Posts
      Update:
      It seems to pass the placeholder correct the first time. But not the second time.

      I am trying to list say 10 items.
      The code below is used to query the database, and set the placeholders (Yes, using sql here but normally xpdo. )

      foreach($modx->query($sql_get_srqs) as $srq) {
      	
      	$extra_extended=$srq['extra_extended'];
      	$extra_extended=json_decode($extra_extended,true);
      
      	$output_to_serviceRequests= array(
      		'srq_id' 			=> 		$srq['srq_id'],
      		'srq_title' 		=> 		$srq['srq_title'],
      		'srq_info'			=> 		$srq['srq_info'],
      		'srq_type'			=> 		$srq['srq_type'],
      		'srq_created_on'	=> 		$srq['srq_created_on'],
      		'srq_expire_on'		=> 		$srq['srq_expire_on'],
      		'srq_category'		=> 		$srq['srq_category'],
      		'srq_budget'		=> 		$srq['extra_budget'],
      		'extended_info'		=>		$extra_extended['btax_businfo'],
      		'srq_zip'			=> 		$srq['loc_zip'],
      		'srq_state'			=> 		$srq['loc_state'],
      		'srq_city'			=> 		$srq['loc_city'],
      	);
      	
      	$output.=$modx->getChunk('chunk_show_srq', $output_to_serviceRequests);
      }
      
      echo $output;
      
      return;
        --------------------------------------
        www.williamastrom.se
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        That would only work if the second chunk was within the first chunk. An element's placeholder is only valid in the element, since the element itself processes the value. To create a global placeholder you need to use the modX.placeholders API functions http://rtfm.modx.com/display/revolution20/modX.setPlaceholders
          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
          • 36562
          • 94 Posts
          Not really sure what you mean by ut being inside the first chunk, i believe it is.

          Let us say :

          <!-- Chunk A begins -->
          [[+this_is_a_value_that_is_passed_and_shows]]
          
          [[$b? &output=`[[+this_is_a_value_that_is_passed_and_shows]] `]
          
          <!-- End of Chunk A -->
          
          <!-- Chunk B begins -->
          [[+output]]
          <!-- End of Chunk B -->


          I am calling B from within A. But B doesn't show the placeholder.

          Thank you for the link, i will go and have a look on it!

          /Will
            --------------------------------------
            www.williamastrom.se
            • 3749
            • 24,544 Posts
            I can't follow what your're trying to do, but it sounds like you might want a $_SESSION variable that is saved by one snippet and updated by another snippet.

            You could also try using $modx->setPlaceholder('key', $value) as long as all operations take place during the same request.

            You could also do all the work in one snippet that creates gets whatever html it needs with getChunk() and sets the output using str_replace on the placeholders.



            ---------------------------------------------------------------------------------------------------------------
            PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
            MODx info for everyone: http://bobsguides.com/modx.html
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 36562
              • 94 Posts

              Sorry for not describing it better.

              I have a snippet, where i get all my data needed from my external table.

              I get a product a time from my external table, i then pass those data to a chunk.

              The chunk successfully shows all the information.

              But since depending on the output to the chunk, i use output filters inside it.

              The main chunk is the "template" and then i have a "content" part, where different kind of products show different kind of info.
              Therefore, instead of organizing this main chunk with:

              [[+placeholder:is=`value`:then=`
              Lots of html and other placeholders
              `]]
              
              [[+placeholder:is=`value`:then=`
              Lots of html and other placeholders
              `]]


              I would like to pass data from this chunk, to a subchunk. like this ( thought it would work ):

              [[+placeholder:is=`value`:then=`
              [[+subchunk? &subchunkplaceholder=`[[+placeholder that works in the main chunk]]` ]]
              `]]
              
              [[+placeholder:is=`value`:then=`
              [[+subchunk? &subchunkplaceholder=`[[+placeholder that works in the main chunk]]` ]]
              `]]
              



              Ive tested alot, and it seems like it works for the first product. But not the following that use this main chunk.

              Therefore i displayed the snippetcode i use to get data from my external tables, output it to the chunk, and then put that output in an $output.= variable and in the end echo that.

              $myProducts=$modx->getCollection('Product');
              foreach($myProducts as $product) {
              	$fields = $product->toArray();
              	$output .= $modx->getChunk('product_container', $fields);
              }
              echo $fields
              


              Is this easier to understand what i mean?
                --------------------------------------
                www.williamastrom.se
                • 22303 MODX Staff
                • 10,725 Posts
                Since MODX processes tags in source order, including nested tags recursively, you do not need to "pass" the placeholder. The nested chunks will already have access to the properties set in the outer chunk; just reference the placeholders inside the nested chunk and call it non-cacheable if necessary, e.g.

                [[!$newchunk]]
                  • 36562
                  • 94 Posts
                  Ahh. Thanks a lot. That worked!
                    --------------------------------------
                    www.williamastrom.se