1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-08 14:16:46 +02:00

Content: getBlock() method added

This commit is contained in:
Awilum
2018-05-16 10:15:55 +03:00
parent f9c8197187
commit f9fca941c2

View File

@@ -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'));
});
}