Page 1 of 1

Cache a Smarty block function

Posted: Tue Jun 05, 2012 7:43 am
by pmw
I use GeSHi as syntax highlighter. But GeSHi is very slow, so I want to cache my Smarty block function and not to call this function for every page visitor. How can I make Smarty to cache the result of my block function?

Code: Select all

<?php
  require_once(dirname(__FILE__) .'/geshi/geshi.php');

  function smarty_block_code($params, $content, &$smarty)
  {
    if (isset($content) && isset($params['lang'])) {
      $geshi = new GeSHi($content, $params['lang']);
      $geshi->enable_classes(true);
      $geshi->enable_keyword_links(false);
      $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
      return $geshi->parse_code();
    }
  }
  ?>

Re: Cache a Smarty block function

Posted: Sat Aug 11, 2012 2:22 am
by calguy1000
In CMSMS 1.11, plugins named smarty_xxxx are cachable by default. However the site developer must enable smarty caching for the site, and enable caching on the appropriate page(s).

functions named smarty_cms_xxxx will not be cachable.

Re: Cache a Smarty block function

Posted: Sat Feb 02, 2013 7:06 pm
by pmw
I tried to upgrade to CMSMS 1.11.4, but the caching doesn't work. I have enabled "Enable Smarty Caching" and have cleared the template cache. But CMSMS still doesn't cache my block function :(

The name of my function is "smarty_block_code". So it should be cached by default.

Re: Cache a Smarty block function

Posted: Fri Feb 08, 2013 10:48 am
by pmw
I have submitted the problem as bug: http://dev.cmsmadesimple.org/bug/view/8918