diff --git a/core/lib/Drupal/Core/Template/Loader/StringLoader.php b/core/lib/Drupal/Core/Template/Loader/StringLoader.php
index 6325b9e98a..fa66047109 100644
--- a/core/lib/Drupal/Core/Template/Loader/StringLoader.php
+++ b/core/lib/Drupal/Core/Template/Loader/StringLoader.php
@@ -20,7 +20,7 @@
  * @see \Drupal\Core\Render\Element\InlineTemplate
  * @see twig_render_template()
  */
-class StringLoader implements \Twig_LoaderInterface, \Twig_ExistsLoaderInterface {
+class StringLoader implements \Twig_LoaderInterface, \Twig_ExistsLoaderInterface, \Twig_SourceContextLoaderInterface {
 
   /**
    * {@inheritdoc}
@@ -36,6 +36,9 @@ public function exists($name) {
 
   /**
    * {@inheritdoc}
+   *
+   * @deprecated in Drupal 8.4.0, will be removed before Drupal 9.0.0. Kept for
+   * backwards compatibility with Twig <= 1.26.0.
    */
   public function getSource($name) {
     return $name;
@@ -44,6 +47,13 @@ public function getSource($name) {
   /**
    * {@inheritdoc}
    */
+  public function getSourceContext($name) {
+    return new \Twig_Source($name, $name);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
   public function getCacheKey($name) {
     return $name;
   }
