$Id: PROGRAMMING.txt,v 1.3 2005/02/21 13:08:14 axel Exp $

SIMPLE RULES OF SNIPPET PROGRAMMING

Because snippet code executes in Drupal framework, then all Drupal API
available. Internally snippets are become as functions. You write
snippet code between <?php ... ?> and let name to snippet function (name
must be unique). During text filtering snippets codes inserts to text 
of messages as function definitions. Example:

1. You write snippet with code <?php phpinfo(); ?> and name it as 'example'
2. In text will inserted definition (function names always prefixed 
with 'snippet_'):
   <?php function snippet_example($SNIPPET_NAME, $SNIPPET_PARAMS,
                                  $SNIPPET_MACRO) { ?>
   <?php phpinfo(); ?>
   <?php } ?>
3. Definition inserted once, but calls to this function may be multiple
   in one message:
   [example] -> 
     <?php print_r(snippet_example('example', array(), 'example')); ?>
   [example|par1|par2] ->
     <?php print_r(snippet_example('example', array([0] => 'par1',
                                                    [1] => 'par2'),
                                              'example|par1|par2')); ?>

As you see parameters of macro transferred to your snippet as function
parameters and you may use them as any other PHP-variables inside you
code.

You should return text prepared by you snipped if want to display
results:

  return $output;

Though you may also directly print it from you snippet with print or echo.

Use static variables to transfer parameters between snippet calls.

Ability to use other snippets from snippet will added in future.

Also in future versions become next additional variables:

SNIPPET_FILES	(become in beta)
FULLTEXT	(become in beta)

Result of snippet will be formatted with filters which used you site,
of course 'Snippet macros' must be one of these filters else you get
PHP-source on output instead of result of execution.

See more useful examples of snippets in EXAMPLES.txt
