recuperer_fond

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).

Example

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

  1. $code = recuperer_fond("inclure/inc-liste-articles", array(
  2. 'id_rubrique' => $id_rubrique,
  3. ));

Download

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).

  1. $infos = recuperer_fond('ki',array(),array('raw'=>true));
  2. spip_log($infos,'test');

Download

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

  1. 'texte' => 'hop
  2. ',
  3. 'squelette' => 'html_1595b873738eb5964ecdf1955e8da3d2',
  4. 'source' => 'sites/tipi.magraine.net/squelettes/ki.html',
  5. 'process_ins' => 'html',
  6. 'invalideurs' =>
  7. 'cache' => '',
  8. ),
  9. 'entetes' =>
  10. 'X-Spip-Cache' => 36000,
  11. ),
  12. 'duree' => 0,
  13. 'contexte' =>
  14. 'lang' => 'en',
  15. 'date' => '2009-01-05 14:10:03',
  16. 'date_redac' => '2009-01-05 14:10:03',
  17. ),
  18. )

Download

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

Translations : English, français