Created
November 20, 2013 13:32
-
-
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.
This file contains 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 | |
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