Another function which is extremely important within SPIP, recuperer_fond(), is used to return the results of compiling a given template. This is sort of the same as for <INCLURE{fond=name} /> used in templates but in PHP.

It accepts from 1 to 4 parameters:

  • the name and address of the source code file (without extension)
  • the compilation context (key/value table)
  • a table of options
  • the name of the connection file for the database to be used

Simple usage

The data returned is the code generated by the compilation output:

  1. $code = recuperer_fond($name, $context);

Advanced usage

The raw option set to true will provide, rather than just the generated code, a table of items calculated by the compilation, which also includes the code (with the key texte).

What does this table contain then? The text, the address of the template source (tagged "source"), the filename of the PHP cache generated by the compilation (tagged "squelette"), an indicator of the presence of PHP in the generated cache file (tagged "process_ins"), and various other values included in the compilation context (the language and data are automatically added since they have not been passed as parameters).


Retrieve the contents of a file /inclure/inc-liste-articles.html by passing the identifier of the desired section (rubrique) in the context:

$code = recuperer_fond("inclure/inc-liste-articles", array(
	'id_rubrique' => $id_rubrique,

Using the raw option:
Here is a small test with a template called "ki.html" containing only the text "hop". In this example, the results are output to a log file called (tmp/test.log).

$infos = recuperer_fond('ki',array(),array('raw'=>true));

These are the results that will be output to tmp/test.log:

array (
  'texte' => 'hop
  'squelette' => 'html_1595b873738eb5964ecdf1955e8da3d2',
  'source' => 'sites/',
  'process_ins' => 'html',
  'invalideurs' => 
  array (
    'cache' => '',
  'entetes' => 
  array (
    'X-Spip-Cache' => 36000,
  'duree' => 0,
  'contexte' => 
  array (
    'lang' => 'en',
    'date' => '2009-01-05 14:10:03',
    'date_redac' => '2009-01-05 14:10:03',

Author Mark Baber Published : Updated : 30/05/10

Translations : English, français