Added TweetExtension
This commit is contained in:
parent
ad6a00b003
commit
1ed53d7357
8 changed files with 59 additions and 14 deletions
44
src/AppBundle/Twig/TweetExtension.php
Normal file
44
src/AppBundle/Twig/TweetExtension.php
Normal 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';
|
||||
}
|
||||
|
||||
}
|
|
@ -3,6 +3,10 @@ services:
|
|||
class: AppBundle\Twig\SpeakerDeckExtension
|
||||
tags:
|
||||
- { name: twig.extension }
|
||||
app.twig.tweet:
|
||||
class: AppBundle\Twig\TweetExtension
|
||||
tags:
|
||||
- { name: twig.extension }
|
||||
app.twig.vimeo:
|
||||
class: AppBundle\Twig\VimeoExtension
|
||||
tags:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue