Dieses Plugin für Smarty macht das hervorheben von Quelltext bequem vom Template aus möglich.
Dazu muss man die Pfadangabe in Zeile 28 bearbeiten, damit GeSHi eingebunden werden kann.

Um Probleme zu vermeiden sollte man die literal tags von Smarty innerhalb des code Tags verwenden.

  1. /**
  2.  * Smarty {code lang="php" numbers="1"}{/code} block plugin
  3.  *
  4.  * Type: block function<br>
  5.  * Name: code<br>
  6.  * Purpose: format text a certain way with preset styles
  7.  * or custom wrap/indent settings<br>
  8.  * Requires: GeSHi http://qbnz.com/highlighter/
  9.  * alter the path to the GheSHi file
  10.  * @param array
  11.  * <pre>
  12.  * Params: lang: string programming language
  13.  * numbers: integer (0)
  14.  * file: path to file instead content
  15.  * </pre>
  16.  * @author Johannes 'Banana' Keßler mail at bananas-playground dot net
  17.  * @param content string to highlight
  18.  * @param Smarty clever simulation of a method
  19.  * @return string string $content re-formatted
  20.  */
  21. function smarty_block_code($params, $content, &$smarty) {
  22. if(is_null($params['file'])) {
  23. if (is_null($content) || is_null($params['lang'])) {
  24. return;
  25. }
  26. }
  27.  
  28. require_once("path/to/geshi.php");
  29. if($params['file'] != "") {
  30. $high = new GeSHi("",$params['lang']);
  31. $high->load_from_file($params['file']);
  32. }
  33. else {
  34. $high = new GeSHi($content,$params['lang']);
  35. }
  36.  
  37. if($params['numbers'] == "1") {
  38. $high->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
  39. }
  40.  
  41. $text = $high->parse_code();
  42.  
  43. return $text;
  44. }