We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14883 ☆ A M B ☆
    • 450 Posts
    I want to do something like $chunk = $modx->getObject('modChunk', array('name'=>$chunkName));

    but I also want to specify a certain property set, akin to
    [[$chunkName@myPropertySet]]

    How do I do that?
      • 14883 ☆ A M B ☆
      • 450 Posts
      oops - modx tag disappeared;

      should read "akin to [ [$chunkName@myPropertySet] ]
        • 22303 MODX Staff
        • 10,725 Posts
        In MODX 2.1 and previous releases there is no easy way to do this, but this is already possible in develop (MODX 2.2.0-dev) using the getElement() method that was added in MODX 2.1. This is preferable to using getObject to retrieve a Chunk as it utilizes the parser's sourceCache and prevents unnecessary queries to the database.

        <?php
        $chunk = $modx->parser->getElement('modChunk', $chunkName);
        return $chunk->process($properties);
        

        So in 2.1, you would have to manually get the property set and pass the properties explicitly to the process() method.

        In 2.2, you can include PropertySets and Output Filters in the name, just as it would be in the parsing of a tag:

        <?php
        $chunk = $modx->parser->getElement('modChunk', "{$chunkName}:{$filter}@{$propertySetName}");
        return $chunk->process($properties);
        
          • 14883 ☆ A M B ☆
          • 450 Posts
          Sweet. Thank you!