Skip to content

Commit 6dd3023

Browse files
committed
add new twitter property to generate custom HTML
1 parent 5316d2c commit 6dd3023

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/TwitterProperty.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Astrotomic\OpenGraph;
4+
5+
class TwitterProperty extends Property
6+
{
7+
/** @var string */
8+
protected $prefix = 'twitter';
9+
10+
public function __toString(): string
11+
{
12+
$content = str_replace('"', '&quot;', $this->content);
13+
14+
return "<meta name=\"{$this->prefix}:{$this->property}\" content=\"{$content}\">";
15+
}
16+
}

src/TwitterType.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,14 @@ public function image(string $image, ?string $alt = null)
4545

4646
return $this;
4747
}
48+
49+
public function setProperty(string $prefix, string $property, string $content)
50+
{
51+
$this->tags[$prefix.':'.$property] = TwitterProperty::make($prefix, $property, $content);
52+
}
53+
54+
public function addProperty(string $prefix, string $property, string $content)
55+
{
56+
$this->tags[] = TwitterProperty::make($prefix, $property, $content);
57+
}
4858
}

0 commit comments

Comments
 (0)