From f9fca941c263546aa0933c02f7960deb35803d8e Mon Sep 17 00:00:00 2001 From: Awilum Date: Wed, 16 May 2018 10:15:55 +0300 Subject: [PATCH] Content: getBlock() method added --- flextype/Content.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/flextype/Content.php b/flextype/Content.php index 78d721a8..79de1ed9 100755 --- a/flextype/Content.php +++ b/flextype/Content.php @@ -232,6 +232,24 @@ class Content return $pages; } + /** + * Get block + * + * $block = Content::getBlock('block-name'); + * + * @access public + * @param string $block_name Block name + * @return string + */ + public static function getBlock($block_name) : string + { + if (Filesystem::fileExists($block_path = PATH['blocks'] . '/' . $block_name . '.md')) { + return Content::processContent(Filesystem::getFileContent($block_path)); + } else { + throw new \RuntimeException("Block does not exist."); + } + } + /** * Returns $shortcode object * @@ -362,7 +380,7 @@ class Content }); Content::shortcode()->addHandler('block', function(ShortcodeInterface $s) { - return $s->getParameter('name'); + return Content::getBlock($s->getParameter('name')); }); }