Silverstripe Version: 4.9
Question: How can I get breadcrumbs to display in a Layout template for a DataObject as a page?
I have a DataObject for “Articles” that I am displaying as a page. The articles have sub classes (e.g. Recipe or Event) and the page template so the layout template are determined dynamically based on the subclass.
This works (mostly) using this to return the page:
ArticleController.php
...
$breadcrumbs = $article->Breadcrumbs();
$layoutData = ArrayData::create([
'Article' => $article,
]);
$pageData = ArrayData::create([
'Title' => $article->Title,
]);
return $this->customise([
'Layout' => $this->renderWith($layoutTemplate, $layoutData)
])->renderWith($pageTemplate, $pageData);
I get the $breadcrumbs data from my Article as an ArrayList (as shown above). The breadcrumbs are included by adding $Breadcrumbs
as normal in the Layout .ss template.
But if I just add the $breadcrumbs as-is straight into $layoutData:
$layoutData = ArrayData::create([
'Article' => $article,
'Breadcrumbs' => $breadcrumbs
]);
Then I get the error:
the method ‘forTemplate’ does not exist on 'SilverStripe\ORM\ArrayList’
So I feel like I need to do something like:
$breadcrumbs->renderWith('BreadcrumbsTemplate')
But I don’t know where to put that (if that is how it works) and feel I have gone down a bit of a rabbit hole
Any suggestions would be appreciated.