Skip to content

Commit

Permalink
Add exception handler for bad yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
Elliot Mitchum committed Feb 8, 2016
1 parent ac30362 commit f67660f
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions view.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use \Grav\Common\Plugin;
use \Grav\Common\Grav;
use \Grav\Common\Page;
use OAuth\Common\Exception\Exception;
use \Symfony\Component\Yaml\Yaml as YamlParser;

class ViewPlugin extends Plugin
Expand Down Expand Up @@ -115,13 +116,20 @@ private function getParams($page) {

// Check for params in page header.
if (isset($page->header()->view['params'])) {
// Convert from Yaml.
if (is_readable($page->header()->view['params'])) {

// Try to convert Yaml.
try {
$params = (array) YamlParser::parse($page->header()->view['params']);
// Items are needed. Get page children by default.
if (!isset($params['items'])) {
$params['items'] = '@self.children';
}
}

// Else throw warning.
catch(\Exception $e) {
$this->grav['messages']->add('Caught exception: ' . $e->getMessage() . "\n");
}

// Items are needed. Get page children by default.
if (!isset($params['items'])) {
$params['items'] = '@self.children';
}
}

Expand Down

0 comments on commit f67660f

Please sign in to comment.