Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This allows a frontmatter.yaml file to be included in a page folder #775

Merged
merged 4 commits into from
Apr 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}