We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34120
    • 236 Posts
    I’ve got a ditto call which pulls in a chunk, the chunk contains a snippet call with TVs. The TVs aren’t making it through to ditto. I think from what I’ve read it’s because you need to use placeholders with Ditto? Anyway, it will be easier if I post it:

    [!Ditto?parents=`5` &depth=`1` &orderBy=`menuindex ASC` &tpl=`2ndHandDitt` !]

    2ndHandDitt.tpl
    <div class="product_data"> 
    	[+content+]
    	[[productInfo? &size=`[*size*]` &weight=`[*weight*]` ]]
    </div>

    productInfo snippet
    $size = $modx->getTemplateVar('size');
    $weight = $modx->getTemplateVar('weight');
    
    if (!empty($size['value'])) {
    	echo "<h6>Size: </h6>" . $size['value'];
    	}	
    if (!empty($weight['value'])) {
    	echo "<h6>Weight: </h6>" . $weight['value'];
    	}
    return;


    [+content+] works as you would expect as it’s a placeholder, size and weight don’t work. If I change them to placeholders then they aren’t processed in the snippet. This might be a simple fundamental I’m missing, any help appreciated.

    Many thanks in adavance.
      • 26931
      • 2,314 Posts
      try adding Ditto’s hiddenFields parameter -> http://ditto.modxcms.com/files/snippet-ditto-php.html#hiddenFields
        • 4172
        • 5,888 Posts
        maybe this is what you need:

        <div class="product_data"> 
        	[+content+]
        	[+size:isnot=``:then=`<h6>Size: </h6>[+size+]`+]
                [+weight:isnot=``:then=`<h6>Weight: </h6>[+weight+]`+]
            
        </div>


        you can control the output with phx, and use [+.......+] for Tvs in Ditto, if you want to get the TVs from listed resources and not from the main-resource.
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 34120
          • 236 Posts
          Many thanks both
          I didn’t have any joy with the hiddenFields.

          Bruno yours works great, thanks!
          <div class="product_data"> 
          	[+content+]
          	[+size:isnot=``:then=`<h6>Size: </h6>[+size+]`+]
                  [+weight:isnot=``:then=`<h6>Weight: </h6>[+weight+]`+]
              
          </div>

          This chunk only works when called by ditto, if I just call it as a chunk it doesn’t work. Is this because ditto supports phx? I don’t have phx installed.

          Thanks for you time and help
            • 4172
            • 5,888 Posts
            in a resource directly, you need [*...........*] instead of [+..........+]. And yes, this works then only, if you have phx installed, without ditto.
            So you have several ways to do it now.

            1. Use Ditto to list the content of your main-resource. So you can use the same chunk.

            [!Ditto? &documents=`[*id*]` &tpl=`.....`  ..........!] 


            2. install phx and use two different chunks for ditto and normal content.
            3. install phx and use one chunk for both in some way like that:

            <div class="product_data"> 
            	[+content:isnot=``:then=`[+content+]`:else=`[*content*]`+]
            	[+size:isnot=``:then=`<h6>Size: </h6>[+size+]`+]
                    [*size:isnot=``:then=`<h6>Size: </h6>[*size*]`*]
                    [+weight:isnot=``:then=`<h6>Weight: </h6>[+weight+]`+]
                    [*weight:isnot=``:then=`<h6>Weight: </h6>[*weight*]`*]
                
            </div>


            4. use your snippet and two different chunks:
            $tv = $modx->getTemplateVarOutput(array('size','weight'));
            $output='';
            if (!empty($tv['size'])) {
            	$output.= "<h6>Size: </h6>" . $tv['size'];
            	}	
            if (!empty($tv['weight'])) {
            	$output.= "<h6>Weight: </h6>" . $tv['weight'];
            	}
            return $output;


            of course there are a lot of more ways to get there.



              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 34120
              • 236 Posts
              Thanks bruno, great clear post. That has helped me loads, I went with option 1 and it’s working great.

              of course there are a lot of more ways to get there.
              This is one of the reasons modx is so great but also why I tend to get a bit lost at times.

              Thanks again, huge help.