diff --git a/docs/reference/twig_helpers.rst b/docs/reference/twig_helpers.rst
index 226fcd12..8364036b 100644
--- a/docs/reference/twig_helpers.rst
+++ b/docs/reference/twig_helpers.rst
@@ -16,6 +16,19 @@ This will render the page title as follows:
My custom title
+Render the page title text
+^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+.. code-block:: twig
+
+ {{ sonata_seo_title_text() }}
+
+This will render the page title as follows:
+
+.. code-block:: html
+
+ My custom title
+
Render page metadata
^^^^^^^^^^^^^^^^^^^^
diff --git a/src/Twig/Extension/SeoExtension.php b/src/Twig/Extension/SeoExtension.php
index b38d0649..03ad99b2 100644
--- a/src/Twig/Extension/SeoExtension.php
+++ b/src/Twig/Extension/SeoExtension.php
@@ -45,6 +45,7 @@ public function getFunctions()
{
return [
new TwigFunction('sonata_seo_title', [$this, 'getTitle'], ['is_safe' => ['html']]),
+ new TwigFunction('sonata_seo_title_text', [$this, 'getTitleText'], ['is_safe' => ['html']]),
new TwigFunction('sonata_seo_metadatas', [$this, 'getMetadatas'], ['is_safe' => ['html']]),
new TwigFunction('sonata_seo_html_attributes', [$this, 'getHtmlAttributes'], ['is_safe' => ['html']]),
new TwigFunction('sonata_seo_head_attributes', [$this, 'getHeadAttributes'], ['is_safe' => ['html']]),
@@ -83,6 +84,11 @@ public function getTitle()
return sprintf('%s', strip_tags($this->page->getTitle()));
}
+ public function getTitleText(): string
+ {
+ return $this->page->getOriginalTitle();
+ }
+
/**
* NEXT_MAJOR: remove this method.
*
diff --git a/tests/Twig/Extension/SeoExtensionTest.php b/tests/Twig/Extension/SeoExtensionTest.php
index 3fc4c1b0..2f8471e2 100644
--- a/tests/Twig/Extension/SeoExtensionTest.php
+++ b/tests/Twig/Extension/SeoExtensionTest.php
@@ -55,6 +55,16 @@ public function testTitle()
static::assertSame('foo bar', $extension->getTitle());
}
+ public function getTitleText(): void
+ {
+ $page = $this->createMock(SeoPageInterface::class);
+ $page->expects(static::once())->method('getTitle')->willReturn('foo bar');
+
+ $extension = new SeoExtension($page, 'UTF-8');
+
+ static::assertSame('foo bar', $extension->getTitleText());
+ }
+
public function testEncoding()
{
$page = $this->createMock(SeoPageInterface::class);