Hello,
In this site, there are some pages that contain a single text block, such as ‘privacy’ or ‘terms and conditions’. I’d rather have these texts in a single field, at site level, within a tab in the panel, than create a page for each of them, and have them next to main site sections.
So I turn to virtual pages. My reasoning is, I create a simple virtual page for ‘/privacy’ and within its ‘content’ I grab the text from $site->privacyText()
or similar. But I also need translations, so perhaps something like:
return [
'routes' => [
[
'pattern' => '(:any)/privacy',
'action' => function () {
return Page::factory([
'slug' => 'privacy',
'template' => 'privacy',
'translations' => [
'en' => [
'code' => 'en',
'content' => [
'title' => 'Privacy',
'text' => site()->content('en')->privacy()
]
],
'es' => [
'code' => 'es',
'content' => [
'title' => 'Privacidad',
'text' => site()->content('es')->privacy()
]
],
'ca' => [
'code' => 'ca',
'content' => [
'title' => 'Privacitat',
'text' => site()->content('ca')->privacy()
]
],
],
]);
}
]
]
];
…would this be correct? should I be using content() like that? or should I use translation()? Is there a simpler way ? Can I actually query a field within the content of a virtual page?
Does that fallback to default lang in case there is no such content in that lang? If not, how to?
Thank you