Skip to content

Instantly share code, notes, and snippets.

@Codenator81
Created June 22, 2014 16:44
Show Gist options
  • Save Codenator81/904c20dc9ba8a518668d to your computer and use it in GitHub Desktop.
Save Codenator81/904c20dc9ba8a518668d to your computer and use it in GitHub Desktop.
CacheSnippetTwig
<?php
public function getFunctions()
{
return array(
new Twig_SimpleFunction('snippetC', function ($snippetName, $params = array()) {
global $modx;
$cacheManager = $modx->getCacheManager();
if($snipetFromCache = $cacheManager->get($snippetName)){
return $snipetFromCache;
} else {
$modx->getParser();
$snippet = $modx->runSnippet($snippetName, $params);
$cacheManager->set($snippetName,$snippet);
return $snippet;
}
}),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment