page_variables
Within the /boot/site.yml there is a page_vars
element. This element contains all per-template variables, such as page title and layouts, although can be expanded to include any per-template variables desired. Each child elment is an associative array, the keys being the name of the template file being rendered, and the value being anything you wish. Each array should also contain a "default" element for any templates rendered that do not exist within the array.
For an example of a 'contact_email' variable:
page_vars:
contact_email:
locations/houston.html: [email protected]
locations/chicago.html: [email protected]
locations/houston.html: [email protected]
default: [email protected]
The above registers the page variable contact_email
with four items, three that correspond with a specific template file, and one default item. You may obtain the specific variable using the SyrusAdapter::getPageVar() method, for example:
use Apex\App\Adapters\SyrusAdapter;
class myClass
{
#[Inject(SyrusAdapter::class)]
private SyrusAdapter $adapter;
/**
* Process
*/
public function process():void
{
$email = $this->adapter->getPageVar('contact_email');
echo "E-Mail for this page is $email\n";
}
}
With the above code, $value
would be the value of the correct key within the contact_email
array of the YAML file for the page currently being rendered.