Anybody an idea how I can find a page object and then pass it as a page reference field, tried several things but it’s not working out atm
The endgoal is that I want to find the page object for ‘jobs’ and then pass it with a block that uses it to link to that specific page.
$jobsPage = site()->find('jobs');
$block = \Page::factory([
'slug' => 'virtualWorkWithUs',
'template' => 'block-center',
'content' => [
'showLogo' => true,
'blockBgcolor' => $bgcolor,
'blockPreTitle' => __('Join our team'),
'blockTitle' => __('Werken bij Studiebureau Rimanque?'),
'blockText' => __('text'),
'buttonToggle' => true,
'buttonLinkToggle' => true,
'buttonText' => 'Join our team',
'buttonLinkPage' => $jobsPage,
return snippet('blocks/block-center', compact('block'));
I think I’m missing some context here, is that a block for the new blocks field? A virtual page?
Allright, bit more context then. I use pages as blocks to dynamically build them. So a block is a page template.
In the Center type block there’s a possibility to add a button
Now I want to dynamically add a specific “filled in” block to certain pages, that’s why I’m dynamically building that page. And in this Page object i Need to pass the Page link as shown in the panel above. But I want to do this with code and that’s where I’m struggling. I can get the page but I get a page object, how can I translate this to content of a Page field.
Am I making any sense here?
A page field stores an array of page ids in yaml format. So that’s exactly what you need to pass to it:
'buttonLinkPage' => Data::encode([$jobsPage->id()], 'yaml'),