Skip to content

Instantly share code, notes, and snippets.

@Cuboctaedro
Created November 20, 2013 13:32
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save Cuboctaedro/7563228 to your computer and use it in GitHub Desktop.
Save Cuboctaedro/7563228 to your computer and use it in GitHub Desktop.
An extension of Kirbytext for creating a custom "figure" tag for images with complex captions.
<?php
class kirbytextExtended extends kirbytext {
function __construct($text, $markdown=true) {
parent::__construct($text, $markdown);
$this->addTags('figure');
$this->addAttributes('caption', 'credits');
}
function figure($params) {
global $site;
$page = ($this->obj) ? $this->obj : $site->pages()->active();
$image = $page->images()->find($params['figure']);
$defaults = array(
'caption' => '',
'credits' => ''
);
// merge the given parameters with the default values
$options = array_merge($defaults, $params);
$imageurl = $image->url() ;
$imagecaption = $options['caption'] ;
$imagecredits = $options['credits'] ;
return '<figure><img src="' . $imageurl . '" alt="' . $imagecaption . '"><figcaption><span class="caption">' . $imagecaption . '</span><span class="image-credits">' . $imagecredits . '</span></figcaption></figure>';
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment