We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6038
    • 228 Posts
    Ok - i’m struggling here...

    I’ve created a snippet that uses the api to generate a ditto call, which works great. Now I want the chunk that ditto uses for the ’tpl’ parameter to be parsed for a custom placeholder before it is passed on to ditto.

    Why don’t i just use a TV for each document to supply the value? Because the value can be one of several values for each document, depending on context of where it is viewed in the site. Its a category list, basically, and a product can appear in several categories, but in each instance I want to show something in the ditto output that only shows the current category.

    // replace the custom parameter in the original chunk before passing to ditto.
    $p['currentCategory'];
    $new_chunk = $modx->parseChunk('original_chunk', $p, '{+', '+}');
    
    // run the ditto part
    $params = array(
    'parents' => 3,
    'display' => 'all',
    'tpl' => $new_chunk,
    'extenders' => 'tagging',
    'tagData' => 'solutionCategories',
    'tags' => $solution_cat,
    'tagDelimiter' => ','
    );
    
    $out = $modx->runSnippet('Ditto', $params);
    
    return $out;


    When i echo the chunk once i’ve done my replacement, the other placeholders are gone, but if I die with the chunk in the same spot, the placeholders are still there...?
    Either way, the result is my parsed chunk is not accepted by ditto - i get the ’&tpl either does not contain any placeholders or is an invalid chunk name, code block, or filename. Please check it.’ message.


    I’m stuck on understanding why my parsed chunk - using custom placeholder characters - is not returning a usable string. And why echo/die show different results.
      • 6038
      • 228 Posts
      ok thanks for listening... i solved it.
      i wasn’t using the ’@CODE:’ prefix in ditto, where a literal string is used instead of a chunk name.
      Oh the shame.

      so, for the record, it should have been:
      // run the ditto part
      $params = array(
      'parents' => 3,
      'display' => 'all',
      'tpl' => '@CODE:'.$chunk,
      'extenders' => 'tagging',
      'tagData' => 'solutionCategories',
      'tags' => $solution_cat,
      'tagDelimiter' => ','
      );


      Edit: why is it that when you spend hours trying to figure something out, you figure it out seconds after finally posting for help?