Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@svenhanssen
Last active December 10, 2015 06:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save svenhanssen/4397316 to your computer and use it in GitHub Desktop.
Save svenhanssen/4397316 to your computer and use it in GitHub Desktop.
Embed snippets right into your Kirbytext flavored content. Handy for including dynamic content. For example, just call (snippet: articles limit: 5) to include the articles.php snippet and limit those articles by 5.
<?php
/*
Add this file to your site/snippets directory.
All attributes defined in kirbytext.extended.php will be available right here.
*/
$articles = $pages->find( "articles" )->children()->visible()->flip()->limit( $limit );
foreach ($articles as $article):
?>
<article>
<h1><?php echo $article->title(); ?></h1>
<?php echo kirbytext( $article->text() ); ?>
</article>
<?php
endforeach;
?>
(snippet: articles limit: 4)
<?php
/*
Add this file to your site/plugins directory and add your own custom attributes to the addAtributes function, otherwise Kirby will ignore the whole tag.
*/
class kirbytextExtended extends kirbytext {
function __construct($text, $markdown = true) {
parent::__construct($text, $markdown);
// define custom tags
$this->addTags('snippet');
// define custom attributes
$this->addAttributes('limit');
}
function snippet( $params ) {
return snippet( $params["snippet"], $params, true );
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment