highlight

Modifier that highlight a string of PHP code.

This modifier is useful when you want to display some example of PHP code.

It is possible to download this modifier from [here].

Author: [Davide 'Design' Muzzarelli]

<?php
/*
 * Smarty plugin
 * -------------------------------------------------------------
 * File:     modifier.highlight.php
 * Type:     modifier
 * Name:     highlight
 * Purpose:  highlight a string of PHP code
 *
 * @link http://www.dav-muz.net/
 * @version 1.0
 * @copyright Copyright 2011 by Davide Muzzarelli
 * @author Davide Muzzarelli <d.muzzarelli@dav-muz.net>
 * @license New BSD
 *
 * @param string containing var-attribute
 * @return string highlighted HTML text inside a "code" tag
 * -------------------------------------------------------------
 */
function smarty_modifier_highlight($string)
{
    return highlight_string($string, true);
}
?>

Example from a string assigned to Smarty:

{$php_code|highlight}

Another example inside a template:

<pre>
{capture assign=code}{literal}
  <?php
  # Example of PHP code to highlight
  echo 'Hello';
  ?>
  {/literal}{/capture}{$code|highlight}
</pre>

Back to SmartyPlugins?.