Browse by Month RSS Feed
  • September 2010
  • August 2010
  • July 2010
  • May 2010
  • April 2010
  • March 2010

  • GeSHi Smarty PluginOctober 25, 2008
    Filed under: Software @ 5:15 pm

    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

    1. Download the zipfile. It contains a single file: block.geshi.php.
    2. Upload the PHP file to your Smarty plugins folder.
    3. Ensure that GeSHi is installed somewhere on your site.
    4. 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!

    Comments (1)


    Filed under: Data Generator @ 12:23 am

    Okay, the site’s up and running again. Bah, what a dreadful site migration.

    Comments (1)


    generatedata.com back soon…October 5, 2008
    Filed under: Data Generator @ 3:12 pm

    Blurghhh… despite assurances from my host that all will be well, my attempt to move generatedata.com to a new host has gone up in smoke. The site should be hopefully back on line soon. Apologies to all.

    Comments (0)