diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d73e2e2a..c293c0c99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * Added new `Collection::toExtendedArray()` method that's particularly useful for Json output of data * Added new `|yaml_encode` and `|yaml_decode` Twig filter to convert to and from YAML * Added new `read_file()` Twig function to allow you to load and display a file in Twig (Supports streams and regular paths) + * Added a new `Medium::exists()` method to check for file existence 1. [](#improved) * Better `Page.collection()` filtering support including ability to have non-published pages in collections diff --git a/system/src/Grav/Common/Page/Medium/Medium.php b/system/src/Grav/Common/Page/Medium/Medium.php index 55281bed5..d02a43163 100644 --- a/system/src/Grav/Common/Page/Medium/Medium.php +++ b/system/src/Grav/Common/Page/Medium/Medium.php @@ -92,6 +92,20 @@ public function meta() return new Data($this->items); } + /** + * Check if this medium exists or not + * + * @return bool + */ + public function exists() + { + $path = $this->get('filepath'); + if (file_exists($path)) { + return true; + } + return false; + } + /** * Returns an array containing just the metadata *