Skip to content

Commit

Permalink
Merge pull request #775 from getgrav/feature/default-frontmatter-yaml
Browse files Browse the repository at this point in the history
This allows a frontmatter.yaml file to be included in a page folder
  • Loading branch information
rhukster committed Apr 13, 2016
2 parents c8e86dc + 8bdceb6 commit 3535c55
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
9 changes: 9 additions & 0 deletions system/src/Grav/Common/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,15 @@ public function getKey()
return $this->key;
}

/**
* Setter method to set key (Advanced)
*/
public function setKey($key)
{
$this->key = $key;
$this->driver->setNamespace($this->key);
}

/**
* Helper method to clear all Grav caches
*
Expand Down
10 changes: 10 additions & 0 deletions system/src/Grav/Common/Page/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,16 @@ public function header($var = null)
$this->raw_content = $file->markdown();
$this->frontmatter = $file->frontmatter();
$this->header = (object)$file->header();

// If there's a `frontmatter.yaml` file merge that in with the page header
// note page's own frontmatter has precedence and will overwrite any defaults
if (!Utils::isAdminPlugin()) {
$frontmatter_file = $this->path . '/' . $this->folder . '/frontmatter.yaml';
if (file_exists($frontmatter_file)) {
$frontmatter_data = (array)Yaml::parse(file_get_contents($frontmatter_file));
$this->header = (object)array_replace_recursive($frontmatter_data, (array)$this->header);
}
}
} catch (ParseException $e) {
$file->raw(Grav::instance()['language']->translate([
'FRONTMATTER_ERROR_PAGE',
Expand Down
6 changes: 1 addition & 5 deletions system/src/Grav/Common/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,7 @@ public function config()
*/
public function isAdmin()
{
if (isset($this->grav['admin'])) {
return true;
}

return false;
return Utils::isAdminPlugin();
}

/**
Expand Down
14 changes: 14 additions & 0 deletions system/src/Grav/Common/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -622,4 +622,18 @@ public static function verifyNonce($nonce, $action)
//Invalid nonce
return false;
}

/**
* Simple helper method to get whether or not the admin plugin is active
*
* @return bool
*/
public static function isAdminPlugin()
{
if (isset(Grav::instance()['admin'])) {
return true;
}

return false;
}
}

0 comments on commit 3535c55

Please sign in to comment.