I’m working on an existing Kirby 1 site that needs to switch the content directory per-user. The client would like to serve different content based on the user’s location.
I’ve added code in the
panel/index.php files that will detect the ip and sets the
$rootContent variable but it doesn’t seem to be working as I expected.
I guess I’m confused on how Kirby is initialized and configured, is it once for every user, or is per-user configuration possible?
Should I be calling
c::set('root.content', $rootContent); instead of just setting the
Thanks in advance!
$rootContent is correct. In the end it doesn’t matter whether you use
c::set(), because that will get overridden by the
system.php file with the value of
How exactly does it not work as expected? Do you get an error or is is just using the default directory/ignoring your custom setting?
BTW: Just a general thought on your approach: Using the IP address of the visitor as a hint for the geographical location is not always reliable. And in the situation when the auto-detection fails, there would be no way for the user to correct his/her location.
Thanks so much for the reply @lukasbestle! The site will have a ui option to switch locales, that’s the part that doesn’t seem to work… switching on the fly…
Is there a session var or does Kirby stay “glued” to a certain content dir for the current user?
The assignment seemed to work the first time but then never changes even when manually changing the value through url param.
Kirby does not store anything about the content directory in the user’s session (as far as I remember Kirby 1 doesn’t even create sessions by default).
So it depends on the code you use. Could you please post your
index.php and other relevant files for your content setup?
Thanks again @lukasbestle I was able to figure it out. I’m a php n00b and didn’t realize that I had to call
session_start on every page I accessed the session variable on.