core-bundle/src/Resources/contao/controllers/BackendPreview.php
public function run()
	{
		$objRouter = System::getContainer()->get('router');

		// Switch to a particular member (see #6546)
		if ($strUser = Input::get('user'))
		{
			$objAuthenticator = System::getContainer()->get('contao.security.frontend_preview_authenticator');

			if (!$objAuthenticator->authenticateFrontendUser($strUser, false))
			{
				$objAuthenticator->removeFrontendAuthentication();
			}

			$arrParameters = array();

			if (Input::get('url'))
			{
				$arrParameters['url'] = Input::get('url');
			}

			if (Input::get('page'))
			{
				$arrParameters['page'] = Input::get('page');
			}

			return new RedirectResponse($objRouter->generate('contao_backend_preview', $arrParameters));
		}

		$objTemplate = new BackendTemplate('be_preview');
		$objTemplate->base = Environment::get('base');
		$objTemplate->language = $GLOBALS['TL_LANGUAGE'];
		$objTemplate->title = StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['fePreview']);
		$objTemplate->host = Environment::get('host');
		$objTemplate->charset = Config::get('characterSet');
		$objTemplate->site = Input::get('site', true);
		$objTemplate->switchHref = $objRouter->generate('contao_backend_switch');
		$objTemplate->user = System::getContainer()->get('contao.security.token_checker')->getFrontendUsername();

		$strUrl = null;

		if (Input::get('url'))
		{
			$strUrl = Environment::get('base') . Input::get('url');
		}
		elseif (Input::get('page'))
		{
			$strUrl = $this->redirectToFrontendPage(Input::get('page'), Input::get('article'), true);
		}
		else
		{
			$event = new PreviewUrlConvertEvent();
			System::getContainer()->get('event_dispatcher')->dispatch(ContaoCoreEvents::PREVIEW_URL_CONVERT, $event);
			$strUrl = $event->getUrl();
		}

		if ($strUrl === null)
		{
			$strUrl = System::getContainer()->get('router')->generate('contao_root', array(), UrlGeneratorInterface::ABSOLUTE_URL);
		}

		$objTemplate->url = $strUrl;

		return $objTemplate->getResponse();
	}
public function run()
	{
		$objRouter = System::getContainer()->get('router');

		// Switch to a particular member (see #6546)
		if ($strUser = Input::get('user'))
		{
			$objAuthenticator = System::getContainer()->get('contao.security.frontend_preview_authenticator');

			if (!$objAuthenticator->authenticateFrontendUser($strUser, false))
			{
				$objAuthenticator->removeFrontendAuthentication();
			}

			$arrParameters = array();

			if (Input::get('url'))
			{
				$arrParameters['url'] = Input::get('url');
			}

			if (Input::get('page'))
			{
				$arrParameters['page'] = Input::get('page');
			}

			return new RedirectResponse($objRouter->generate('contao_backend_preview', $arrParameters));
		}

		$objTemplate = new BackendTemplate('be_preview');
		$objTemplate->base = Environment::get('base');
		$objTemplate->language = $GLOBALS['TL_LANGUAGE'];
		$objTemplate->title = StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['fePreview']);
		$objTemplate->host = Environment::get('host');
		$objTemplate->charset = Config::get('characterSet');
		$objTemplate->site = Input::get('site', true);
		$objTemplate->switchHref = $objRouter->generate('contao_backend_switch');
		$objTemplate->user = System::getContainer()->get('contao.security.token_checker')->getFrontendUsername();

		$strUrl = null;

		if (Input::get('url'))
		{
			$strUrl = Environment::get('base') . Input::get('url');
		}
		elseif (Input::get('page'))
		{
			$strUrl = $this->redirectToFrontendPage(Input::get('page'), Input::get('article'), true);
		}
		else
		{
			$event = new PreviewUrlConvertEvent();
			System::getContainer()->get('event_dispatcher')->dispatch(ContaoCoreEvents::PREVIEW_URL_CONVERT, $event);
			$strUrl = $event->getUrl();
		}

		if ($strUrl === null)
		{
			$strUrl = System::getContainer()->get('router')->generate('contao_root', array(), UrlGeneratorInterface::ABSOLUTE_URL);
		}

		$objTemplate->url = $strUrl;

		return $objTemplate->getResponse();
	}
Run the controller and parse the template

@return Response