We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14617
    • 47 Posts
    Hi all

    I have a problem when i create snippets that loop through TVs, set placeholders and then output a chunk based on those placeholders. The code looks like this:

    <?php
    for ($i=1; $i <= 3; $i++) { 
    	$startValue = $modx->getTemplateVarOutput('travel_'.$i.'_startDate');
    	$startValue = $startValue['travel_'.$i.'_startDate'];
    	
    	$endValue = $modx->getTemplateVarOutput('travel_'.$i.'_endDate');
    	$endValue = $endValue['travel_'.$i.'_endDate'];
    	
    	$guide = $modx->getTemplateVarOutput('travel_'.$i.'_guide');
    	$guide = $guide['travel_'.$i.'_guide'];
    		
    	if (strlen($startValue) != 0 && strlen($endValue) != 0) {
    		$modx->setPlaceholder('startDate', $startValue);
    		$modx->setPlaceholder('endDate', $endValue);
    		$modx->setPlaceholder('guide', $guide);
    		
    		echo $modx->getChunk('travelDatesRow');
    	}
    }
    ?>


    This will output:
    12-01-2009 - 31-01-2009 with: Guide Name
    12-01-2009 - 31-01-2009 with: Guide Name

    because my chunk (travelDatesRow) look like this:
    [+startDate+] - [+endDate+] with: [+guide+]


    My problem is that only the values of the LAST TV entries are outputtet. It is not being outputtet as the loop goes through the different TVs (see how the values are the same. It is not set that way in the document).

    I am calling the snippet uncached...

    Any help is greatly appreciated.
    Jonas
      • 14617
      • 47 Posts
      DOH. I just found the answer. I will now answer my own thread:

      Use parseChunk instead of getChunk.
        • 7231
        • 4,205 Posts
        So you changed this:
        echo $modx->getChunk('travelDatesRow');
        to this:
        echo $modx->parseChunk('travelDatesRow');
          [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]
          • 14617
          • 47 Posts
          Well yes. But don’t you need the extra parameters...?:
          echo $modx->parseChunk('travelDatesRow', $modx->placeholders, '[+', '+]');
            • 5789
            • 21 Posts
            You just saved me HOURS of frustration. Ran into the exact thing.
              --
              Modx 2.0.2
              Win 7 Firefox 3.6.10
              Mac Snow Leopard Firefox 3.5.12
              • 8991
              • 2 Posts
              Same here.

              I too needed the extra params to make it work. Thanks all!

              Quote from: jonasgrau at Sep 22, 2008, 07:33 AM

              Well yes. But don’t you need the extra parameters...?:
              echo $modx->parseChunk('travelDatesRow', $modx->placeholders, '[+', '+]');