Skip to content

Instantly share code, notes, and snippets.

@jrast
Created June 14, 2012 21:47
Show Gist options
  • Save jrast/2933178 to your computer and use it in GitHub Desktop.
Save jrast/2933178 to your computer and use it in GitHub Desktop.
Tutorial: ShortCodes in Silverstripe
<?php
// ...
ShortcodeParser::get()->register('Gist', array('ShortCodeHandler', 'GistShortCodeHandler'));
<script src="http://gist.github.com/{$GistID}.js<% if File %>?file=$File<% end_if %>"></script>
<-- Hier kommt dann das Template hin -->
[Gist id=2933178 file=ShortCode.txt]
<?php
class ShortCodeHandler {
public static function GistShortCodeHandler($arguments, $caption = null, $parser = null) {
if (empty($arguments['id']))
return;
$customise = array();
$customise['GistID'] = $arguments['id'];
$customise['File'] = key_exists('file', $arguments) ? $arguments['file'] : false;
$template = new SSViewer('Gist');
return $template->process(new ArrayData($customise));
}
}
<?php
class ShortCodeHandler {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment