3.1.8. cacheUnique()

void cacheUnique ( [string $id] )

Sometimes we store different contents in a specified template. To cache all the variants of the data assigned to a template, we specify an unique content ID using this method. If no parameter specified, the ID utility is disabled.

Let's say we have three articles displayed with article.tpl template. All of them must be cached. This example shows, how to do it:

Example 3.4. cacheUnique()

  $tpl -> cacheStatus(true, 30);
  // Store the article 1
  $tpl -> cacheUnique(1);
  $tpl -> assign('content', $article1);
  $tpl -> parse('article.tpl');
  // Store the article 2
  $tpl -> cacheUnique(2);
  $tpl -> assign('content', $article2);
  $tpl -> parse('article.tpl');
  // Store the article 3
  $tpl -> cacheUnique(3);
  $tpl -> assign('content', $article3);
  $tpl -> parse('article.tpl');

More details about output caching in Output caching in OPT chapter.

Note: this method is not available, if the Output Caching was removed from the source with OPT Configurator.