Added TweetExtension

This commit is contained in:
Oliver Davies 2016-03-29 10:11:37 +01:00
parent ad6a00b003
commit 1ed53d7357
8 changed files with 59 additions and 14 deletions

View file

@ -0,0 +1,44 @@
<?php
namespace AppBundle\Twig;
use Twig_Extension;
use Twig_SimpleFunction;
class TweetExtension extends Twig_Extension
{
/**
* {@inheritdoc}
*/
public function getFunctions()
{
return [
new Twig_SimpleFunction('tweet', [$this, 'render']),
];
}
/**
* Render a tweet.
*
* @param string $tweet
* The content of the tweet.
*
* @return string
*/
public function render($tweet)
{
return sprintf(
'<blockquote class="twitter-tweet" lang="en"><p lang="en" dir="ltr">%s</blockquote>',
$tweet
);
}
/**
* {@inheritdoc}
*/
public function getName()
{
return 'tweet';
}
}