mirror of
https://github.com/flextype/flextype.git
synced 2025-08-29 07:50:29 +02:00
@@ -45,7 +45,56 @@ class Snippets
|
||||
|
||||
$vars['fetch'] = $id;
|
||||
|
||||
return $this->_fetch_snippet($vars);
|
||||
return $this->_display_snippet($vars);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch snippet
|
||||
*
|
||||
* @access public
|
||||
* @param string $id Snippet id
|
||||
* @return array|false The entry contents or false on failure.
|
||||
*/
|
||||
public function fetch(string $id)
|
||||
{
|
||||
$snippet_file = Fieldsets::_file_location($id);
|
||||
|
||||
if (Filesystem::has($snippet_file)) {
|
||||
if ($snippet_body = Filesystem::read($snippet_file)) {
|
||||
return $snippet_body;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch Snippets
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function fetchList() : array
|
||||
{
|
||||
$snippets = [];
|
||||
|
||||
// Get snippets files
|
||||
$_snippets = Filesystem::listContents($this->_dir_location());
|
||||
|
||||
// If there is any snippets file then go...
|
||||
if (count($_snippets) > 0) {
|
||||
foreach ($_snippets as $snippet) {
|
||||
if ($snippet['type'] == 'file' && $snippet['extension'] == 'json') {
|
||||
$snippet_content = JsonParser::decode(Filesystem::read($snippet['path']));
|
||||
$snippet[$snippet['basename']] = $snippet_content['title'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// return snippets
|
||||
return $snippets;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -15,7 +15,7 @@ namespace Flextype;
|
||||
use Thunder\Shortcode\ShortcodeFacade;
|
||||
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
|
||||
|
||||
// Shortcode: [snippets fetch=snippet-name]
|
||||
// Shortcode: [snippets id=snippet-name]
|
||||
$flextype['shortcodes']->addHandler('snippets', function(ShortcodeInterface $s) use ($flextype) {
|
||||
return $flextype['shortcodes']->fetch($s->getParameter('fetch'));
|
||||
return $flextype['shortcodes']->display($s->getParameter('id'));
|
||||
});
|
||||
|
Reference in New Issue
Block a user