I have a "general" layout template, in which I would like to define a general set of options to pass to all the forms I'm creating in the specialized templates the contain the blocks I'm fetching:
<?php
$formOptions = [
'id' => 'page-content-form',
'name' => 'page-content-form',
];
echo $this->fetch('h4');
echo $this->fetch('form-start');
echo $this->fetch('form-fields');
I have multiple templates like this one, all with slight differences in the blocks (that are not relevant to this question):
<?php
$this->extend('/element/layout/page_content_form');
$this->append('h4');
echo $this->Html->tag('h4', 'Title');
$this->end();
$this->append('form-start');
echo $this->Form->create($pageContent, $formOptions);
$this->end();
$this->append('form-fields');
// more code here...
$this->end();
However, this gives me a Undefined variable $formOptions
warning and a [TypeError] Bootstrap4\View\Helper\FormHelper::create(): Argument #2 ($options) must be of type array, null given
error.
I have tried adding $this->set('formOptions', $formOptions)
to the layout template, but that didn't fix the issue.
What's the way of correctly passing or sharing variables between different blocks of my view?