abdellahramadan / open-graph-bundle
A bundle to add open-graph to a website
Installs: 10
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- symfony/dependency-injection: ^5.4 || ^6.0 || ^7.0
- symfony/http-kernel: ^5.4 || ^6.0 || ^7.0
- twig/twig: ^3.0
Requires (Dev)
- phpstan/phpstan: ^2.1
- symfony/phpunit-bridge: ^7.2
- symfony/test-pack: ^1.0
README
Install with Composer
composer require abdellahramadan/open-graph-bundle
Usage
Add to template file
Add {{ open_graph() }}
to the base template or any page where the meta information will be injected
Add meta inforation
In your controller, type-hint OpenGraphInterface
Example
class HomeController extends AbstractController
{
public function index(OpenGraphInterface $openGraph): Response
{
$openGraph
->setTitle('My website')
->setDescription('Some descriptions ...')
->setSiteName('My Blog')
;
...
return $this-render('index.html.twig');
}
}
This will render
<meta property="og:title" content="My website">
<meta property="og:description" content="Some descriptions ...">
<meta property="og:site_name" content="My Blog">
You can add structured data
$openGraph->addStructuredProperty('image', 'secure_url', 'https://mysite.com/test.jpg')
this will render
<meta property="og:image:secure_url" content="https://mysite.com/test.jpg" />
Add Twitter card
->addTwitterCardProperty('description', 'This is an example X(Twitter) Card
will render
<meta name="twitter:description" content="This is an example X(Twitter) Card)" />