We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9768
    • 13 Posts
    [Modx Revolution 2.0.7-pl(advanced) on Windows XPPro-SP3 with Apache 2.2.17.0, PHP 5.3.3, MySQL 5.1.52 with pdo/mysql. Browsers: Opera v11.10 and Chrome 8.0.552.237]

    I’m trying to use a Custom Output Filter (snippet) while displaying rows from a database table. The displaying Resource invokes a Snippet which retrieves a (selection from) the table, and presents it using a row-format passed in as a parameter to the Snippet call. This all works fine, as long as I only want to display the data unchanged. However, if the tags in the format have output filters, then the output filter snippet is not passed a $input value as documented, so can’t do the desired edit.

    I made a simple mock-up using a Snippet that just presents a constant row, as though it had retrieved it from the modx_actions table, and using the built-in "incr" and "ucase" filters. They don’t work either.

    Is this a restriction (and if so I can’t find it documented) or a bug (perhaps in the "process" method of "chunk")?

    Mock-up code:
    (a) Resource:
    <table>
    <tbody>
    <tr>
    <th>ID</th><th>IDplus</th><th>Controller</th><th>CONTROLLER</th>
    </tr>
    [[!listActions?format=`
    <tr>
    <td>[[+id]]</td>
    <td>[[+id:incr=`1`]]</td>
    <td>[[+controller]]</td>
    <td>[[+controller:ucase]]</td>
    </tr>
    `]]
    </tbody>
    </table>

    (b) Snippet "listActions":
    <?php
    /* for demo purposes, just set up array as though we had retrieved from db */
    
    $data = array('id'=>43, 'controller'=>'workspaces/package/view');
    
    $useChunk = $scriptProperties['format'];
    
    $chunk = $modx->newObject('modChunk');
    $chunk->setCacheable(false);
    echo $chunk->process($data, $useChunk);

    Result (extract from page source):
    [tt]<table>
    <tbody>
    <tr>
    <th>ID</th><th>IDplus</th><th>Controller</th><th>CONTROLLER</th>
    </tr>

    <tr>
    <td>43</td>
    <td>1</td>
    <td>workspaces/package/view</td>
    <td></td>
    </tr>

    </tbody>
    </table>[/tt]
    Expected result would include "44" instead of "1" and "WORKSPACES/PACKAGE/VIEW" instead of empty.
      • 22295
      • 153 Posts
      $useChunk = $scriptProperties[’format’];
      $chunk = $modx->newObject(’modChunk’);
      $chunk->setCacheable(false);
      echo $chunk->process($data, $useChunk);

      as a start, replace all the above with a simple:
      $result = $modx->getChunk('chunkName', $data)
      

      then after - start dealing with uncached placeholders and performance questions - if they’ll be relevant.

      btw, always return $result, don’t echo it.