DEVTRENCH.COM

MODx Chunk Cache Plugin

I needed to cache a chunk as a file so that another application (an ecommerce store) could include that file as well. I wrote this plugin that does that:

$chunks = array('StoreMenu'); // array of chunks that need to be cached
foreach($chunks as $v)
{
  $res = $modx->db->select("snippet","modx_site_htmlsnippets","name = '$v'");
  if($modx->db->getRecordCount($res))
  {
    $output = $modx->db->getValue($res);
    $fh = fopen($modx->config['base_path'].$v.'.html','w');
    fwrite($fh,$output);
    fclose($fh);
  }
}

Configure this chunk to have the OnChunkFormSave system event an whenever a chunk is saved it will write the specified chunks to the file system.