We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40748
    • 55 Posts
    Hello everyone!

    Can anybody please explain me what 'snippet' field does or means when creating a (temporary) Chunk object via API?

    $fields = array(
      'name' => 'chunk2015',
      'snippet' => 'snippetName'
    );
    $chunk = $modx->newObject('modChunk');
    $chunk->fromArray($fields);
    


    I'm creating dashboatd widget and found piece of code like this.
    But could not find the idea behind 'snippet' filed in this case.

    Thank you!

    This question has been answered by wshawn. See the first response.

      Cheap and ready landing pages: http://real-portal.biz
      Start selling fast, good for dropshipping
    • discuss.answer
      • 32699 ☆ A M B ☆
      • 427 Posts
      Its the content of the chunk and can also be referred to by its alias: content.


        Get your copy of MODX Revolution Building the Web Your Way http://www.sanitypress.com/books/modx-revolution-building-the-web-your-way.html

        Check out my MODX || xPDO resources here: http://www.shawnwilkerson.com
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        Chunks used to be called "htmlsnippets". The content field being named "snippet" is just a holdover from those days.
          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
          • 3749
          • 24,544 Posts
          The proper way to set the content of a chunk is with:

          $chunk->setContent('Some Content');
          


          If you want the raw, unprocessed content of the chunk, use this:

          $content = $chunk->getContent();


          You can also use this to get the content with any MODX tags processed:

          $content = $modx->getChunk('ChunkName');


          And you can add values for any placeholder tags by doing this:

          In the chunk:

          <p>Placeholder one: [[+placeholder1]]</p>
          <p>Placeholder two: [[+placeholder2]]</p>
          


          In your snippet:

          $myPlaceholders = array (
               'placeholder1' => 'value1',
               'placeholder2' => 'value2',
               // etc.
          );
          
          $content = $modx->getChunk('ChunkName', $myPlaceholders);
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting