Last active
December 10, 2015 06:49
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(snippet: articles limit: 4) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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