styliser

This pipeline modifies the way in which SPIP searches for the template to use to compute a page - and for example, to change it for a specific section.

You can use it like this :

// pipeline styliser
$template = pipeline('styliser', array(
	'args' => array(
		'id_rubrique' => $sectionId,
		'ext' => $ext,
		'fond' => $initialTemplate,
		'lang' => $lang,
		'connect' => $connect
	),
	'data' => $template,
));

It receives some arguments found in the environment context and returns the name of the template that will be used by the compilation.

If the url is spip.php?article18, the arguments will be :

  • id_rubrique = 4 (if the article is in section number 4)
  • ext = ’html’ (the default extension for templates)
  • fond = ’article’ (name of the template initially used)
  • lang = ’fr’
  • connect = ’’ (SQL connection name).

Example :

The plugin "Spip-Clear" uses this pipeline to call some specific templates for the different branches of the blog:

// defines the template to use for a section of Spip-Clear
function spipclear_styliser($flux){
	// article or section ?
	if (($fond = $flux['args']['fond'])
	AND in_array($fond, array('article','rubrique'))) {
		
		$ext = $flux['args']['ext'];
		// [...]

		if ($section_id = $flux['args']['id_rubrique']) {
			// calculates the branch
			$branch_id = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($section_id));
			// comparison of the branch with the config of Spip-Clear
			if (in_array($branch_id, lire_config('spipclear/secteurs', 1))) {
				// if the template $fond_spipclear exists
				if ($template = test_squelette_spipclear($fond, $ext)) {
					$flux['data'] = $template;
				}
			}
		}
	}
	return $flux;
}

// returns a template $fond_spipclear.$ext when it exists
function test_squelette_spipclear($fond, $ext) {
	if ($template = find_in_path($fond."_spipclear.$ext")) {
		return substr($template, 0, -strlen(".$ext"));
	}
	return false;
}

Author Gilles Vincent Published : Updated : 12/03/23

Translations : English, français