diff --git a/typo3/sysext/frontend/Classes/ContentObject/FluidTemplateContentObject.php b/typo3/sysext/frontend/Classes/ContentObject/FluidTemplateContentObject.php
index 85cae47c41e92fe1b41ad3c8e8a326886de0fa0d..93cec153a85e700e6f638053ad15466300d2729e 100644
--- a/typo3/sysext/frontend/Classes/ContentObject/FluidTemplateContentObject.php
+++ b/typo3/sysext/frontend/Classes/ContentObject/FluidTemplateContentObject.php
@@ -85,12 +85,14 @@ class FluidTemplateContentObject extends AbstractContentObject
      */
     public function render($conf = [])
     {
-        $parentView = $this->view;
-        $this->initializeStandaloneViewInstance();
-
         if (!is_array($conf)) {
             $conf = [];
         }
+        $variables = $this->getContentObjectVariables($conf);
+        $variables = $this->contentDataProcessor->process($this->cObj, $conf, $variables);
+
+        $parentView = $this->view;
+        $this->initializeStandaloneViewInstance();
 
         $this->setFormat($conf);
         $this->setTemplate($conf);
@@ -98,8 +100,6 @@ class FluidTemplateContentObject extends AbstractContentObject
         $this->setPartialRootPath($conf);
         $this->setExtbaseVariables($conf);
         $this->assignSettings($conf);
-        $variables = $this->getContentObjectVariables($conf);
-        $variables = $this->contentDataProcessor->process($this->cObj, $conf, $variables);
 
         $this->view->assignMultiple($variables);
 
diff --git a/typo3/sysext/frontend/Tests/Functional/ContentObject/FluidTemplateContentObjectTest.php b/typo3/sysext/frontend/Tests/Functional/ContentObject/FluidTemplateContentObjectTest.php
index 01d83a88aa150cd950af7c2c5918a09b9d97778d..8edd8e3d21fad93858dc4ee647c4f36143ad4025 100644
--- a/typo3/sysext/frontend/Tests/Functional/ContentObject/FluidTemplateContentObjectTest.php
+++ b/typo3/sysext/frontend/Tests/Functional/ContentObject/FluidTemplateContentObjectTest.php
@@ -21,7 +21,19 @@ use TYPO3\CMS\Frontend\ContentObject\TextContentObject;
  */
 class FluidTemplateContentObjectTest extends \TYPO3\TestingFramework\Core\Functional\FunctionalTestCase
 {
-    protected $coreExtensionsToLoad = ['fluid'];
+    /**
+     * @var array
+     */
+    protected $coreExtensionsToLoad = [
+        'fluid'
+    ];
+
+    /**
+     * @var array
+     */
+    protected $testExtensionsToLoad = [
+        'typo3/sysext/fluid/Tests/Functional/Fixtures/Extensions/fluid_test',
+    ];
 
     /**
      * @test
@@ -64,4 +76,52 @@ class FluidTemplateContentObjectTest extends \TYPO3\TestingFramework\Core\Functi
 
         $this->assertEquals($expectedResult, $result);
     }
+
+    /**
+     * @test
+     */
+    public function renderWorksWithNestedFluidtemplateWithLayouts()
+    {
+        /** @var $tsfe \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController */
+        $tsfe = $this->createMock(\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::class);
+        $GLOBALS['TSFE'] = $tsfe;
+
+        $configuration = [
+            '10' => 'FLUIDTEMPLATE',
+            '10.' => [
+                'template' => 'TEXT',
+                'template.' => [
+                    'value' => '<f:layout name="BaseLayout"/><f:section name="main"><f:format.raw>{anotherFluidTemplate}</f:format.raw></f:section>'
+                ],
+                'layoutRootPaths.' => [
+                    '0' => 'EXT:fluid_test/Resources/Private/Layouts'
+                ],
+                'variables.' => [
+                    'anotherFluidTemplate' => 'FLUIDTEMPLATE',
+                    'anotherFluidTemplate.' => [
+                        'template' => 'TEXT',
+                        'template.' => [
+                            'value' => '<f:layout name="BaseLayout"/><f:section name="main"></f:section>'
+                        ],
+                        'layoutRootPaths.' => [
+                            '0' => 'EXT:fluid_test/Resources/Private/LayoutOverride/Layouts'
+                        ],
+                    ],
+                ],
+            ],
+        ];
+        $expectedResult = 'DefaultLayoutLayoutOverride';
+
+        $contentObjectRenderer = new \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
+        $contentObjectRenderer->setContentObjectClassMap([
+            'FLUIDTEMPLATE' => FluidTemplateContentObject::class,
+            'TEXT' => TextContentObject::class,
+        ]);
+        $fluidTemplateContentObject = new \TYPO3\CMS\Frontend\ContentObject\ContentObjectArrayContentObject(
+            $contentObjectRenderer
+        );
+        $result = preg_replace('/\s+/', '', strip_tags($fluidTemplateContentObject->render($configuration)));
+
+        $this->assertEquals($expectedResult, $result);
+    }
 }