Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include homepage record in Twig globals #1491

Merged
merged 1 commit into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Controller/Frontend/DetailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function contentByFieldValue(string $contentTypeSlug, string $field, stri
return $this->renderSingle($record);
}

public function renderSingle(?Content $record, bool $requirePublished = true): Response
public function renderSingle(?Content $record, bool $requirePublished = true, array $templates = []): Response
{
if (! $record) {
throw new NotFoundHttpException('Content not found');
Expand All @@ -109,7 +109,9 @@ public function renderSingle(?Content $record, bool $requirePublished = true): R
// later on, if we need to get the root record of a page.
$this->twig->addGlobal('record', $record);

$templates = $this->templateChooser->forRecord($record);
if (empty($templates)) {
$templates = $this->templateChooser->forRecord($record);
}

return $this->renderTemplate($templates, $context);
}
Expand Down
10 changes: 7 additions & 3 deletions src/Controller/Frontend/HomepageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ class HomepageController extends TwigAwareController implements FrontendZoneInte
/** @var TemplateChooser */
private $templateChooser;

public function __construct(TemplateChooser $templateChooser)
/** @var DetailController */
private $detailController;

public function __construct(TemplateChooser $templateChooser, DetailController $detailController)
{
$this->templateChooser = $templateChooser;
$this->detailController = $detailController;
}

/**
Expand All @@ -28,7 +32,7 @@ public function __construct(TemplateChooser $templateChooser)
* name="homepage_locale",
* requirements={"_locale": "%app_locales%"})
*/
public function homepage(ContentRepository $contentRepository): Response
public function homepage(ContentRepository $contentRepository, bool $requirePublished = true): Response
{
$homepage = $this->config->get('theme/homepage') ?: $this->config->get('general/homepage');
$params = explode('/', $homepage);
Expand Down Expand Up @@ -58,6 +62,6 @@ public function homepage(ContentRepository $contentRepository): Response

$templates = $this->templateChooser->forHomepage();

return $this->renderTemplate($templates, ['record' => $record]);
return $this->detailController->renderSingle($record, $requirePublished, $templates);
}
}