GeSHi is a free, PHP syntax highlighter – invaluable if you need to display code in your webpages. I use it here and there on this website (like on the various code listings, here) and it really goes a long way to making your code more readable.
Anyway, I’ve now been working on the Form Tools 2 documentation since – what feels like – the dawn of time. The documentation uses Smarty to generate the HTML. Smarty has many plugins available but surprisingly, there wasn’t one for GeSHi integration. So I wrote one. Here it is. Go crazy.
Installation
- Download the zipfile. It contains a single file: block.geshi.php.
- Upload the PHP file to your Smarty plugins folder.
- Ensure that GeSHi is installed somewhere on your site.
- Edit the block.geshi.php file and update the require_once() line, so that it points to your geshi folder.
And you’re done!
Usage
Using it is really simple. It’s implemented as a “block” function – meaning you just wrap your code in the geshi tags and it automatically converts it using GeSHi. Try embedding this in your smarty template (sorry it’s not syntax highlighted!):
{geshi lang=”php”}{literal}
function chicken()
{
echo “chicken!”;
return true;
}
{/literal}{/geshi}
Note the extra {literal} and {/literal} tags. The default tag delimiter for Smarty is the curly brace { and }. Since a lot programming languages use these characters, you’ll need to tell the Smarty engine not to try and convert the code first. Hence the {literal} tags.
If however, you specify your own your right and left Smarty delimiters, the {literal} tags may not be necessary.
The lang parameter is required, and lets GeSHi know which language the code is in.
There are just two additional parameters:
{geshi lang=”php” show_line_numbers=true start_line_numbers_at=X}{literal}
function chicken()
{
echo “chicken!”;
return true;
}
{/literal}{/geshi}
I think they’re self-explanatory.
Anyway, hope this comes in handy!








