API:parseChunk

From MODx Wiki
Jump to: navigation, search
 API Function Definition: 
parseChunk
Versions 
all
Return Values
Success: parsed chunk
Fail: boolean false
Data Type 
string
Object Hierarchy 
DocumentParser
string parseChunk(string $chunkName, array $chunkArr[, string $prefix[, string $suffix]]);


Run through the given chunk ($chunkName), replacing all the indices (plus the $prefix and $suffix) of $chunkArr with their respective values.

  • $prefix & $suffix default to "{" & "}" respectively (minus quotes)
  • $prefix & $suffix default to "+" & "" respectively (minus quotes) for MODx Revolution
  • If $chunkArr is not an array, this functions returns boolean false.

Examples

  1. $output= "<ul id=\"recordlist\">";
  2. for($i=0; $i<count($records);$i++){
  3. $cover=$records[$i][0]['value'];
  4. $id=$records[$i][1]['value'];
  5. $pagetitle=$records[$i][2]['value'];
  6.  
  7. if(!isset($cover) || $cover==""){
  8. $cover=$modx->config['site_url']."assets/images/cover/nocover.gif" ;
  9. }
  10. $chunkArr = array(
  11. 'recordlink' => $modx->makeUrl($id),
  12. 'recordname' => $pagetitle,
  13. 'coverimage' => $cover
  14. );
  15. $output .= $modx->parseChunk('recordList', $chunkArr, '[+', '+]');
  16. }
  17. $output .= "</ul>";

Function Source

File: manager/includes/document.parser.class.inc.php
Line: 1722


Notes

Personal tools