We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28785
    • 7 Posts
    [b]Info:
    promocat is a TV for promotionpages specifiying the section in the website they are meant to appear in
    showpromo is a TV in the pages where the Ditto call is made.

    Can anybody explain why this works:

    (call directly from template)
    [tt][!Ditto? &parents=`14` &filter=`promocat,[*showpromo*],7`!][/tt]

    but this doesn’t
    (snippet called from template)

    [tt]$dittoParams = array(
    ’parents’=>’14’,
    ’filter’=>’promocat,[*showpromo*],7’,

    );
    return $modx->runSnippet(’Ditto’, $dittoParams);[/tt]

    Thx!
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      You can’t have MODx tags in PHP code. Use one of the API functions for getting the value of a given TV for a given document.
        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
        • 28785
        • 7 Posts
        Thanks for the answer. That put me back on track.
        But it’s still not working.
        I have this in the snippet call:

        $[tt]tv = $modx->getTemplateVarOutput(array("showpromo"));
        $showpromo = $tv[’showpromo’];
        $dittoParams = array(
        ’parents’=>’19’,
        ’filter’=>’promocat,$showpromo,7’,
        ’noResults’=>’NO result’,
        ’debug’=>’1’
        );
        return $modx->runSnippet(’Ditto’, $dittoParams);[/tt]

        The variable $showpromo contains the correct value but it doesn’t seem to work in the filter.

        What am I missing here?
          • 16278
          • 928 Posts
          If you look at the Ditto snippet code (parameter processing visible in the manager, not the included PHP files), you’ll see that some parameters, including filters, are turned into quite complex arrays. I haven’t tried it, but it may well be that you have to emulate this to run the snippet through the API.

          Certainly in a Ditto config file you have to feed in parameters such as &orderBy as an array such as
          $orderBy = array('parsed'=>array(), 'custom'=>array(), 'unparsed'=>'pkDate DESC, menuindex DESC');
          and not as the string you would put in a document, so you could test out whether you need such complications by adding $orderBy = ’createdon ASC’ then $orderBy = ’createdon DESC’ to your call, just to see if it works, before diving into the snippet code, if it doesn’t.
          wink KP
            • 4172
            • 5,888 Posts
            'filter'=>'promocat,'.$showpromo.',7',
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 28785
              • 7 Posts
              Thx for your help!
              In concentrating on all the MODX complexities I sometimes seem to forget about the plain PHP syntax rules.