Created
June 22, 2014 16:44
-
-
Save Codenator81/904c20dc9ba8a518668d to your computer and use it in GitHub Desktop.
CacheSnippetTwig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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