public function YAMLFrontMatterExporter::compile in Loft Data Grids 7.2
Build the string content of $this->output and return $this for chaining.
Parameters
mixed $page_id: (Optional) Defaults to NULL. Set this to only compile a single page.
Return value
$this
Overrides ExporterInterface::compile
File
- vendor/
aklump/ loft_data_grids/ src/ AKlump/ LoftDataGrids/ YAMLFrontMatterExporter.php, line 62
Class
- YAMLFrontMatterExporter
- Class YAMLFrontMatterExporter
Namespace
AKlump\LoftDataGridsCode
public function compile($page_id = null) {
$bodyKey = $this->settings->bodyKey;
// We will only operate on the current page.
$data = $this
->getData()
->getPage();
// We ignore all but the first row
$row = reset($data);
$build = array();
$this->output = '';
if ($data) {
$build[] = '---';
if ($build['fm'] = array_diff_key($row, array(
$bodyKey => null,
))) {
$build['fm'] = trim(Yaml::dump($build['fm']));
}
$build[] = '---';
if (empty($build['fm'])) {
$build = array();
}
$build['body'] = isset($row[$bodyKey]) ? $row[$bodyKey] : '';
$this->output = implode(PHP_EOL, $build);
}
return $this;
}