I’m using Kirby as a headless CMS and writing the front-end using Next.js.
To integrate this properly, I’m pointing the “Open” button (in the panel) to my front-end using the page blueprint preview property:
options:
preview: "http://0.0.0.0:3000/{{ kirby.language }}/{{ page.slug }}"
But this only works for development. When this goes live, I’ll want to replace http://0.0.0.0:3000
with something else, say: https://fancyURL.com
.
Usually, I would just replace http://0.0.0.0:3000
with an environment variable and use that to point to any front-end deployment I want at launch time.
But then I usually do this in the context of code.
How can I achieve this in the context of a YAML file?
Could I perhaps get help from Kirby using yml placeholders?
Some thing like preview: "{{ env.frontendurl }}/{{ kirby.language }}/{{ page.slug }}"
?
I thought about using kirby.system.isLocal
, but I just get a 1 or a 0, I don’t think I can build some kind of ternary that I can embed in the yml with this…
1 Like
This just leads back to Kirby. I’m trying to point to my own Next.js front-end deployment, hosted elsewhere.
hmm i guess you could use multi domain configs and put the url in there, then you should be able to access it with something like {{option.siteurl}}
I was a bit vague there… you can create a key value pair in each domain specific config
'siteurl' => 'http://0.0.0.0:3000'
Keep in mind that all configs inherit the main config.php
so you dont need to redefine everything, just the stuff you want to override for a specific domain
Then you should be able to pickup that value in the yaml with {{ option.siteurl }}
1 Like
Ok, this looks like exactly what I need.
So to be extra sure, this siteurl
field would be top level?
config.localhost.php:
<?php
return [
'siteurl' => 'http://0.0.0.0:3000',
...
];
No use config.php
for all which will include localhost then do a config.yourdomain.com.php
that just has the siteurl value redeclared. this will overide that value for that domain only.
Got it. However my question was about where in the returned array my custom siteurl
should be. Top level like my code sample above?
Not sure what you mean exactly there. Once you have those configs set this should do it
options:
preview: "{{ option.siteurl }}/{{ kirby.language }}/{{ page.slug }}"
@texnixe might be able to help more here.
Here is what I have now just to try it out:
site/blueprints/pages/home.yml:
title: Home
options:
preview: "{{ option.siteurl }}/{{ kirby.language }}/{{ page.slug }}"
tabs:
content: tabs/content
header: tabs/header
seotab: seo
site/config/config.php:
<?php
return [
'debug' => true,
'languages' => true,
'panel' => [
'install' => true,
'css' => 'assets/css/panel.css',
],
'markdown' => [
'extra' => true
],
'api' => [
'basicAuth' => true,
'allowInsecure' => true,
],
'siteurl' => 'http://localhost:3000'
]
Yet the “Open” button on the home still just points to 0.0.0.0:8000/en/home
instead of the expected http://localhost:3000/en/home
.
Hrmm… try {{ kirby.option.siteurl }}
Aha, yes! kirby.option('siteurl')
is what did it in the end, thanks a lot!
1 Like